Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [decorator]

The tag has no usage guidance, but it has a tag wiki.

1
vote
0answers
33 views

decouple business logic from supporting logic

To prevent business-logic functions from being bloated with supporting-logic* of shared concerns (e.g. authentication, authorization, logging, profiling, ingress rate-limiting) many backend frameworks ...
0
votes
1answer
128 views

Why isn't there a static initializer in Python?

The equivalent of static { // Code here } does not exist in Python by default. The closest thing, while being "Pythonic", seems to be to create a decorator and do the initialization there such ...
0
votes
1answer
50 views

Wrapping WCF client with Stream for disposing

I need to consume data from a WCF service, which pipes it through a stream. The data itself is contents of an archive file, so it needs additional logic, which I am splitting off into a separate class....
4
votes
6answers
261 views

What pattern can be used instead of these if statements in starbuzz (head first design patterns-Decorator pattern)

Reading Head First Design Patterns. I came to the chapter 3, the Decorator Pattern, Decorator Pattern is very clear for me. but one of the "sharpen your pencil" Our friends at Starbuzz have ...
0
votes
0answers
74 views

Fluent validation - integrate in my business objects best practices

I am involved in the development of a price engine system. I have a set of business objects like Car, Engine, Wheels, etc I want to validate them using the framework Fluent Validation Here an example:...
1
vote
3answers
149 views

Why do we need Decorator Interface?

While going through Decorator Pattern from Wikipedia 1 and reading pattern from Head First Book . One thing that struck me and is missing from both the sources or i may have missed it. Why exactly ...
0
votes
1answer
717 views

Should a Python property decorator be used without a setter or deleter?

I have a class that contains an object (set in this case). The set is modified by the standard function operators __add__ and __sub__, but I also want to explicitly expose a method of getting this ...
1
vote
2answers
789 views

Can the Decorator pattern be used without an interface?

Most of the resources I've seen about the Decorator pattern look like the following: interface Tea { public double cost(); } class BasicTea implements Tea { public double cost() { return 1.99;...
1
vote
1answer
72 views

Should I have entities that automatically persist?

In a MVVM application (Xamarin.Forms, FWIW) I have a viewmodel that stores settings explicitly public class SettingsPageViewMode : INavigatedAware { ISettingsRepository settingsRepository; // ...
4
votes
2answers
165 views

Which pattern should I use for building up a character?

I have an application that lets users create their own character from clothing like hat, pants and facial features, like beard and eyes. I'm using a canvas to display the built up character. The order ...
9
votes
4answers
776 views

Class decorators in Python: practical use cases

I am looking for practical and non-synthetic use cases of Python class decorators. So far, the only case which made sense to me is registering a class in a publisher-subscriber system, e.g. plugins or ...
3
votes
2answers
128 views

deriving , derived decorator classes. How? Does it sound like a good idea or are there more suitable ways?

I follow this example on decorator patterns to implement objects who's functionality can be dynamically be coupled together. Namely: class I: is the interface class, common to both "core" class and "...
9
votes
2answers
426 views

What does it mean to inject data (vs behaviour) in a class constructor, and why is that considered bad practice?

I am reading the book "Learning TypeScript" by Remo Jansen. In one section the author describes how to create a very simple proof-of-concept MVC framework including how to create the Model class and ...
4
votes
1answer
171 views

Does a mutually exclusive Decorator design pattern exist?

We know the Decorator design pattern, but how would someone go about implementing mutually exclusive decorators? Let's say I have a decorator pattern to implement weapon modifiers in a game. The ...
3
votes
1answer
140 views

How to DRY decorator pattern and other delegation in java

I was refactoring some java to use decorators. All of the decorators inherited from a class ThingDecorator, let's say. This consisted entirely of: SomeType methodName(OtherType otherThing) { ...
3
votes
1answer
358 views

Why is abstract Decorator class needed in this example?

Why do we need ShapeDecorator in this design? Why can't we just have RedShapeDecorator implement Shape directly and inherit from Shape?
0
votes
1answer
2k views

Python - Cache function and decorator

I am playing with cache functions using decorators. First, I use a generic function def memorize(func): cache = {} print "printing cache" print cache print "cache printed" ...
3
votes
2answers
1k views

What kind of base for Decorator: interface, abstract class, non-abstract

What should be at the top of inheritance tree of Decorator design pattern? I mean the base for both components and decorators non-abstract class: has data fields, implements methods abstract class: ...
17
votes
6answers
4k views

Is logging next to an implementation a SRP violation?

When thinking of agile software development and all the principles (SRP, OCP, ...) I ask myself how to treat logging. Is logging next to an implementation a SRP violation? I would say yes because ...
2
votes
1answer
535 views

Decorater pattern or strategy pattern

I'm constructing a c# serverside application and I'm trying to do this in a way it can easily be maintained aswell as extended if needed. So what we have is 4 different requests that need to be done (...
1
vote
1answer
685 views

Design pattern where decorated object may ask for things like “status updates” from the decorator to perform it's role?

Here's an situation that has haunted one of my open-source projects for quite some time. Imagine if you could represent every front-end input form with a single backend object? An object that ...
0
votes
1answer
134 views

Is it possible to save and load a decorated object

I am wondering if there is an easy way to save and load a decorated object in c++ as i have never done file handling in C++ before. Currently the only object type I need to save is objects that ...
1
vote
2answers
375 views

Unsure about the decorator design pattern

I'm fairly new at using design patterns and I am currently making a small game for my uni course that I have to use the decorator pattern for creating the different classes of NPC however I think that ...
3
votes
2answers
2k views

Pattern for caching DAOs: strategy or decorator?

I'm building a php system with the Services/DAOs/Domain Models pattern, and now is the time to implement a caching system for the DAOs. Would you use a decorator pattern, or maybe the strategy ...
1
vote
3answers
443 views

Decorator Pattern: can it solve issues arising from changes to underlying code?

I understand that decorators solve the problem of needing to mix and match behaviors, but it was suggested that I could use the decorator pattern to solve issues of brittleness that might arise due to ...
1
vote
1answer
275 views

Decorating a class that calls its own public methods

I've written a system that calculates discounts for a shopping cart based on a set of rules. Each rule is implemented with the following interface (C#): interface IRule { bool IsActive(); bool ...
1
vote
2answers
221 views

How to let the outside world decorate my private field?

Imagine a simple Controller (as in process control) interface. I have some concrete classes, say PIDController, that implement it. I also have some decorator classes that extend these classes somehow,...
0
votes
4answers
2k views

What are the benefits of using a 'decorator factory' that decorates objects?

In a project I decided to implement the Decorator pattern. I have a class Thing with methodA(), and a class AbstractDecorator that inherits from Thing and that all decorators inherit from: ...
6
votes
1answer
9k views

How is the Decorator Pattern actually used in practice? [closed]

I understand completely how to implement the Decorator pattern, and I also understand what it's intent is. The Decorator is used in one of two cases: As an alternative to subclassing - when there ...