jeudi 30 mars 2017

C#: "The Decorator Design Pattern: What is meant by adding functionality?"

I have just gone into studying the Decorator Design Pattern using C#.

I have made an example which kinda functions as i think it is intended except for one thing.

I kinda understood that the whole point of the pattern is to add functionality to an object dynamicly.

So when i create an object like this:

Inventory a = new Ashbringer(new TravelersBagpack());
a.Execute();

Then i kinda expected that the point was that the a object would now be able to call the Execute() method which only exists in the Ashbringer class. Thus adding functionality to the a object.

Though this i can't do without adding the Execute() method to the Inventory interface which would ultimately mean i would have to implement the Execute() method to all the classes implementing Inventory Interface or the abstract Decorator.

Perhaps there is a thing or two i don't know about interfaces or perhaps i miss understand the point of the Decorator Design Pattern?

Aucun commentaire:

Enregistrer un commentaire