Thank you for your opinion. You don’t write the API…
[quote="DanRathbun, post:4, topic:17088"]Why? Because Ruby is a dynamic language, (which means classes can dynamically modified at any time, during runtime,) new Ruby coders are often tempted to (and do) modify both Ruby base classes and SketchUp API classes for there OWN unique uses. This is a no-no! It can (and does often) break everyone's else plugins.
Better that the new coder learn to subclass, and make the modifications to their own unique subclass.[/quote]
[Topic Diversion] please start a new topic titled something similar to
“Dan’s thoughts – never change a SketchUp / Ruby class”
And maybe another topic titled something similar to
“Dan’s thoughts – what Ruby is”
[quote="DanRathbun, post:4, topic:17088"]Now, .. the best reason however (which has not yet been leveraged) is that all observer subclasses can inherited standard functionality, and pass that down to it's "offspring". But usually is not desirable to allow this top most functional definition object to be instantiated. So composition (a Observer mixin module) would be used instead. All the API observer classes would include this module, which makes it appear within all their ancestry chains.Then all custom subclasses would also get the common functionality. They'd get it by subclassing one of the API observer classes, or by explicitly including the common progenitor mixin observer module.[/quote]
[Topic Diversion] please start a new topic titled something similar to
“Dan’s thoughts – proposed additions to the Observer classes”
As to your discussion of a mixin, I suspect some of the code creating the API is not written in Ruby, so let’s leave the implementation to the Trimble SketchUp team.
[quote="DanRathbun, post:4, topic:17088"]What you did is a bit more advanced, because you actually created singleton callback methods instead of instance callback methods.[/quote]
[Edit] I apologize, I was unaware of the term ‘singleton method’. AFAIK, it is a term used only in Ruby, as I can find no other languages where that term is used. As you pointed out, it’s also used in several reflection methods.
If you understand that I was creating methods on the instance object, why mention the concept of modifying SketchUp/Ruby classes?
[quote="DanRathbun, post:4, topic:17088"]Ruby is designed foremost for inheritance, (even though it also has composition capabilities,) ... so teaching and promoting the subclassing protocol (over other methods) to new coders is best, IMO.[/quote]
What if your ‘over other methods’ are commonly used techniques in Ruby, like singleton methods?
[Topic Diversion] please start a new topic (or add to the above) titled something similar to
“Dan’s thoughts – what Ruby is”
My original post was about how to create observer callback methods. Callbacks are a special category of method; for instance, if one subclasses an observer, ‘super’ has no meaning. In other languages (Java, .NET), callbacks would often be implemented as an interface, not as a class. But Ruby doesn’t have implements / interface…
So that leaves two ways to create them, either by subclassing or by using singleton methods.
Greg