0
Which is the name of this Design Pattern
Hi. Previously thought that the Decorator Pattern consisted in attaching something (method | another instance | field,..) to an existing instance. But it ended up being a wrapper that adds functionality, extending without modifying the original. Then, what is the name of the pattern that I confused it with?
8 Respostas
+ 2
Tibor Santa Ausgrindtube
have found a design pattern that looks pretty similar to what I was referring to:
Extension Object
+ 4
Not sure if you find here what you're looking for?
https://youtu.be/tv-_1er1mWI
We need design patterns mostly because changing existing code is difficult and costly. These patterns are "best practices" applied by developers in the real world, that minimize these costs on the long run, if the code needs to be changed. Modifying an existing instance is not a pattern, because this is what we want to avoid... In my opinion.
+ 2
I'm not sure that anybody quite knows what you're writing about. Do you have an example that you can attach here?
Some links?
+ 2
Most modern languages have some sort of "reflection" capability which is able to inject data, new fields etc into instantiated objects at runtime. This can have however serious performance penalties and security risks... But many frameworks rely on such features, like Spring Boot in Java.
https://code.sololearn.com/ca9A17a1A4A1/?ref=app
+ 2
Pity I think the concept of trait, is described in most OOP languages as 'interfaces' or 'mixins', ultimately this problem is solved by inheritance.
In Python there is no separate syntactic element for interfaces, but there is multiclass inheritance.
https://code.sololearn.com/caRd55t9fbHC/?ref=app
https://code.sololearn.com/cChLyLsTJacs/?ref=app
+ 2
Also I think aspect oriented programming (AOP) deals with similar issue, but I have no direct experience with it.
https://en.m.wikipedia.org/wiki/Aspect-oriented_programming
+ 1
Tibor Santa patterns also serve for good design to avoid huge refactoring due to coupling and so.
Ausgrindtube what i describe is like what a trait is in Rust lang
basically have the ability to attach functions and variables to an instance.
But have a dynamic data structure of pointers as instance member to hold such can be non-ideal, i guess.
(but I assume that compilers of languages that support such thigs do it internally)
Not sure if now makes more sense.
0
Tibor Santa forgot provide some info
was concerned mainly to attach stuff at run-time (to avoid waste memory if not needed) so inheritance has some restriction here.
(my concern C# & Rust)