Simple doubt about this use of Decorator in c#

Asked

Viewed 32 times

1

I’m learning to use the pattern in c#, and it’s all flowing very well except for a single question that makes the author of this example, but it is bothering me a lot because I turn the code several times and do not understand why of such statement. Here’s the thing, in this example here:

http://www.macoratti.net/13/02/net_decor1.htm

at the end the author states the following:

"Any optional can be used to decorate any car, provided that the specific car implements a Car type and the optional specific implement the Decoratorcarro type."

Decoratorcarro is in bold..

the intriguing thing is: you can completely take the class Decoratorcarro and that it has no utility at all, code works the same way just enough the optional classes inherit directly from car and I do not understand why the emphasis and the reason for existence of Decoratorcarro

  • 3

    https://i.stack.Imgur.com/Vhjgn.jpg. If it wasn’t useful, it wouldn’t have to exist. It’s only working because it’s not using the actual pattern. The example there may not be good. The worst thing is that almost all examples of PD are bad, in general because one has read somewhere what it is, writes and does not know how to apply it well, can not give a clearer example. And then everyone is talking out of their mouths wanting to use it without even understanding it. And that’s why I don’t answer, I would make the same mistake. I do not remember a case I dared this DP, at least in this exact way. Study the pattern further and you will see usefulness.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.