whats the use of STL?

Started by
19 comments, last by snk_kid 19 years, 9 months ago
Quote:Original post by graveyard filla
Quote:Original post by DigitalDelusion
Define "a lot" it's actually quite easy todo with aggregation and forwarding functions, or if you're sloppy via inheritance abuse.


could you please explain what you mean here? what do you mean by "sloppy inheritense abuse"? would you consider what i posted above in that category? i personally think its very elegant and not sloppy at all, but im a newbie so im not too sure. but it works very well with me for my situation.. flexible and easy to use...

also, if it is or isnt sloppy, could you explain why it is, and what are the alternatives? what is aggregation and forwarding functions? thanks for any help!!


Aggregation is a special form of association that specifies a whole-part relationship between the aggregate (the whole) and the a component (the part). An example of this would be a car type, and car engine type, the car is the whole and a car engine is a part of the car you would say "car has-a engine". This would mean that car has an instance of engine and not a pointer/reference to one which would be an association relationship or "car knows-a engine".

Forwarding functions i think he mean't delegation which means passing/forwarding a message/request to a component to preform an operation on behalf of it. Takening the car & engine example, you may have an operation in car that allows you add fuel to the car but it's really a wrap to a call to an engine instance to do the real adding fuel because the engine knows how to e.g.

class engine {public:  void add_fuel(float) {/* yada yada */}};class car {  engine _eng;public:  car(): _eng() {}  void add_fuel(float amount) {       _eng.add_fuel(amount); //delegate the request  }};


I think by inheritance abuse he means when you do something silly like say have car extend from engine to use it's features or he means ridiclious levels of inheritance say more than 4 levels deep. Aggregation/association & delegation is prefered over inheritance only use inheritance where it makes sense.

It's best to think about types, interfaces/behaviours, various kinds of relationships among types and not to think about implementation to much until you actually do implement.

Weather or not your example code was sloppy sorry i didn't have look at it.

EDIT: callbacks & virtual functions are also a form of delegation, C# has a feature called delegates which you can think of as smart function pointers (i think).

This topic is closed to new replies.

Advertisement