Questions tagged [decorator]
52 questions
5
votes
7
answers
587
views
Exceptions and the Liskov Substitution Principle
Consider the following scenario.
I have an interface IService:
public interface IService
{
void DoSomething();
}
with an implementation:
public class Implementation : IService
{
// This might ...
2
votes
1
answer
144
views
Decorate class which inherits from concrete class(es)
In my project I have several "basic" interfaces whose behavior is fixed, i.e. the default implementation will always be good for every puropse. So I defined them as concrete classes with ...
0
votes
1
answer
250
views
How do we nest decorators?
It is possible to nest many decorators.
@decorator_one
@decorator_two
@decorator_three
@decorator_four
def some_silly_function():
pass
How do we write a decorator class so that the order in which ...
0
votes
0
answers
135
views
Combining Strategy and Decorator pattern (see GOF) to Spectrogram computation
I'm trying to design and develop a software (part of a bigger application) that should compute and render a spectrogram.
The spectrogram can be rendered either from live microphone or a file (assuming ...
2
votes
2
answers
665
views
Replacing the Decorator design pattern with a list of methods
So I've been going over some design patterns and I came across this discussion
https://stackoverflow.com/questions/43565475/using-lists-instead-of-decorator-pattern
I've been thinking that in all ...
-1
votes
1
answer
88
views
How to break a bloated decorator into smaller parts in Django?
In a project I am doing, I have to perform a lot of repetitive checks at the beginning of each API end point. As the amount of duplicate code started to grow, I thought of using a decorator to wrap ...
0
votes
2
answers
205
views
How to refactor code so that a facade class could be decoratable?
I've got a class that is a facade class (encapsulates complex-ish behaviour for reusability). It has a function called manage (the class is called Manager):
function manage()
{
$entityBuilder = '...
-1
votes
1
answer
2k
views
Are there different ways in Python to decorate class methods that dynamically assign themselves to a dict within the class?
Here's what I'd like to do in the form of working code, since it's difficult for me to explain otherwise:
from typing import Callable, Generic, TypeVar
from typing_extensions import Self
# The type ...
0
votes
2
answers
4k
views
Usage of property decorator for private attributes in classes in Python
I've started learning Python recently, and there are some topics I cannot really understand. One is the usage of the decorators in user defined objects, or encapsulation more generally. I mean, let's ...
0
votes
2
answers
652
views
How to solve an issue when a decorator needs variables from the base class?
I have a service class that does some magic. I want to introduce a new type of functionality - raise an event. I am absolutely sure that decorator pattern is great for this scenario. The problem is ...
1
vote
1
answer
370
views
Wrapping methods without Decorator Pattern or AOP
I have a Dao interface which doesn't have any methods defined.
Then I have multiple classes which implement this interface, like PetDao and HouseDao.
For some of the implementation classes, and some ...
2
votes
1
answer
265
views
How can I enforce that decorator pattern is complete at compile time?
I have a C++ class (Class D) that is a decorator of another class (Class B). Class D inherits from B and also requires an instance of B to construct that it keeps track of. Class D overrides all ...
-1
votes
2
answers
962
views
Where to place exception handling while using Decorator design pattern
How to design a service layer structure that will be resistant to exceptions. Let's say I have a simple OrderService service, this service performs basic operations - saving an order.
public interface ...
3
votes
1
answer
168
views
Simplify Decorator Pattern only to Instance and its Decorator
I had some engaging conversation with my co-worker and we've discussed the "proper way" of Decorator Pattern usage. Unfortunately I couldn't find any confirmation of my assumptions and it's ...
4
votes
1
answer
915
views
Cross-cutting concerns and dependency injection
I've got a web application with an architecture somewhat like a front-controller MVC design. I get HTTP requests, route them, run them through a filter layer, dispatch them to my domain classes which ...