存储指令列表
我有一个设计问题。 我有一个 Drawer 类,它调用一种画笔类的一系列方法,并且我有一个要绘制的预定义形状。每个形状都使用抽屉中的实例方法列表。我可以有超过 1 个画笔对象。
我想在运行时在抽屉实例中添加自定义形状,指定新形状的方法列表。
我为每个预定义形状创建了一个类方法,该方法返回带有指令的 BlockClosure。显然我必须将画笔对象作为参数提供给每个 BlockClosure。我想象一个在 Drawer 类的每个实例中包含所有 BlockClosure 的集合。 也许我可以继承 SequenceableCollection 并创建一个指令集合。集合的每个元素都是一条指令,当我实例化这个新集合时,我给出画笔对象。 我真的不知道存储这些步骤的最佳方法。
(也许是共享变量?)
I have a design Problem.
i have a Drawer class wich invokes a serie of methods of a kind-of-brush class and i have a predefined shapes which i want to draw. Each shape uses a list of instance methods from the drawer. I can have more than 1 brush object.
I want to add custom shapes on runtime in the drawer instance, especifying the list of methods of the new shape.
i've created a class method for every predefined shape that returns a BlockClosure with the instruccions. Obviously i have to give to each BlockClosure the brush object as parameter. I imagine a collection with all the BlockClosures in each instance of the Drawer Class.
Maybe i can inherit a SequenceableCollection and make a instruccion collection. Each element of the collection it's a instruction and i give the brush object when i instance this new collection.
I really don't know the best way to store these steps.
(Maybe a shared variable?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以将 ActionSequence 与一些 MessageSend 实例一起使用,并将它们放入抽屉中的字典中(我更喜欢“Painter”作为该类的类名,因为“抽屉”听起来很像我耳朵里的家具部分
:)不太确定你到底想要实现什么。
Maybe you can use anActionSequence with some MessageSend instances and put them in aDictionary in your Drawer (I'd prefer "Painter" as a Classname for that CLass, since "Drawer" sounds much like the furniture part in my ears :)
I'm not realy sure what you want to achieve exactly.
邦焦尔诺,卢西亚诺! La domanda di Lei non è troppo chiara。
呃...我宁愿用英语,我的意大利语有点差。
你的问题不是很清楚。如果我更多地了解您问题的背景,这可能会有所帮助。
您正在开发什么类型的软件?为什么需要“抽屉”(或画家)类的许多实例?
根据我现在的猜测,我认为您需要 Interpreter 模式的某种变体。 “四人帮”一书(设计模式:可重用面向对象软件的元素)是每个程序员的必读之作。
对于 Smalltalkers,我强烈推荐 Sherman Alpert、Kyle Brown 和 Bobby Woolf 撰写的《The Design Patterns Smalltalk Companion》作为日常参考。
抱歉,这就是我目前针对您的问题所能提供的所有建议。
Bongiorno, Luciano! La domanda di Lei non è troppo chiara.
Eh... I'd rather use English, my Italian is somewhat poor.
Your question is not very clear. It could help if I knew more of the context of your problem.
What kind of software are you developing? Why do you need many instances of the 'Drawer' (or Painter) class?
Based on what I was able to guess now, I'd suppose you need some variant of Interpreter pattern. The "Gang of Four" book (Design Patterns: Elements of Reusable Object-Oriented Software) is a must-read for each and every programmer.
For Smalltalkers I highly recommend "The Design Patterns Smalltalk Companion" by Sherman Alpert, Kyle Brown and Bobby Woolf as an everyday reference.
Sorry, this is all advice I can give regarding your problem as it is currently formulated.