Decorator pattern mess

后端 未结 2 1757
南笙
南笙 2021-01-20 03:13

I\'m having a problem figuring out if I\'m using the decorator pattern the right way. Let\'s suppose I\'m working on a console application. In this application I have define

2条回答
  •  难免孤独
    2021-01-20 04:09

    You're not necessarily correct. Rather than decorating object right away, keep some kind of a decoration shema, validatable, lazy, which can be converted into needed (final, ready-to-use) object by calling, let say, .Build(). Just a code sketch: obj.DecorateWith().DecorateWith().DecorateWith(() => new Decorator3(IContainer.Resolve ...).Build(). It makes things definitely harder, however as long as decorating is right way to go and your project is indeed big enough to benefit from such a high abstraction, it will solve your problem.

提交回复
热议问题