What's the equivalent of Composition in BYOND?
In C++ they have something called Composition over inheritance.
How could I achieve this effect with Dream Maker.
Apr 18 2015, 8:59 pm
Best response
|
|
This is the way I like to do it.
|
I should probably combine what you have with setting variables to value of a return of a function for more complete effect. Thanks. Any other suggestions welcome.
Dantum types + return values. Taking datum types to represent static functionality is what you're suggesting. #Subbing in. |
Taking datum types to represent static functionality is what you're suggesting. Yep, that's a very neat way of putting it. I should probably combine what you have with setting variables to value of a return of a function for more complete effect. Can you show me how you did that when/if you do please? I would be interested to see it. |
Sir Quizalot:
Any other suggestions welcome. Composition is pretty much a datum containing other datums. However DM doesn't support interfaces (only inheritance). A crude example: object_a |
In response to Mr_Goober
|
|
You want that to be object1 being composed of an object2 and an object3 though right? (alongside calling the procs within obj1 for obj2 and obj3)
I'm guessing that was a mistake? |
In response to Turboskill
|
|
Turboskill wrote:
You want that to be object1 being composed of an object2 and an object3 though right? (alongside calling the procs within obj1 for obj2 and obj3) Yeah woops. Fixed. |
GatewayRa wrote:
True compositions can't be done in BYOND (well, except by inheritance, but I don't know how that memory is managed in BYOND). True Composition- Composition is most importantly a concept. We can achieve the spirit of any concept in any programming language. Composition- One object can be built of another object. Has ownership. Example video- http://www.lynda.com/Java-tutorials/ Using-aggregation-composition/96949/106092-4.html I really think the best bet is setting variables to function returns. In that sense it may not be inheritance per say. With all of your input I'll figure it out. So thanks. I'm curious if you had to achieve that effect how would you do it Ra besides inheritance? Thanks |
GatewayRa wrote:
He said composition over inheritance, not composition. Actually, he asked about both in the OP. |
GatewayRa wrote:
Flick wrote: I'm not really a programmer. I didn't claim that they gave him correct information, I wouldn't know. All I know about any of it is what I read in the last few hours for my own curiosity, which is why I didn't respond to his questions. Just pointing out that he did actually ask about both, since you stated that he didn't. I'll give that link a read when I get home. Thanks. |
IMO "composition over inheritance" is bad advice--not because it never applies, but because it's as terrible a blanket rule as never using goto. Any organizational method has its strong and weak points, and the key to being a good programmer is predicting which of those points will be most relevant to the project. Composition has strong advantages, but it also has strong disadvantages.
In a language like DM, I don't see that composition's maintenance advantages would be high. The only major purpose to it would be to achieve what single-inheritance cannot. That stackoverflow link is very good though. Definitely worth a quick read. |