Skip to main content

Questions tagged [composition]

Composition means to assemble simpler elements into more complex structures. In OOP, composition usually refers to object composition, i.e. assembling several simpler objects into a a more complex aggregate. It may also refer to an aggregation of object, where the aggregate owns some components.

0 votes
3 answers
2k views

How to solve a circular dependency with a composition relation?

For a game I'm making I have two objects; Gun and ReloadSystem. At the moment, these two object reference each other. Gun tells ReloadSystem to perform a reload when the gun gets clicked, and ...
Boudebouz1's user avatar
2 votes
2 answers
599 views

Is service discovery an anti-pattern?

We deploy microservices in Kubernetes environment. For providing a solution to a business use-case using microservices, Is the idea of service registration and service discovery not an anti pattern? ...
user1787812's user avatar
2 votes
5 answers
846 views

How does inheritance lead to higher coupling than composition?

One major reason for using composition over inheritance is, that inheritance leads to higher coupling. How is that? In both cases members are exposed to the subclass (in case of inheritance) or ...
cobby's user avatar
  • 129
0 votes
1 answer
175 views

What C# Object Composition strategy would you apply for CoreObjects with a governing 'ObjectType' property

In a C# ASP.Net Core Web Application I have a Domain Model CentralDesignObject made up of many component objects & properties, producing a significant amount of derived/calculated values. This ...
freedomdev's user avatar
2 votes
2 answers
503 views

Composition over inheritance: how data are accessed in the composition case?

I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that ...
Andrew Savinykh's user avatar
0 votes
1 answer
114 views

Pitfalls of composition where component is also a component of a sibling component?

I'm relatively new to structuring code in a composition style, and I have a situation where a component is also a component of a sibling component. I'm trying to figure out if there are likely to be ...
Matt Robin's user avatar
0 votes
2 answers
1k views

Inheritance/Composition VS "Direct Injection Construction"

my following example seems to go into the direction Inheritance VS Composition. But that's not, what i want to ask. I see the concept Inheritance and Composition on one side and the alternative, which ...
Robin Kreuzer's user avatar
0 votes
2 answers
237 views

When using composition when to favour wrapper methods?

When using composition, when should we favour wrapper methods? Let's say we have the classic car example. public class Car { private Battery battery; //wrapper method public void load(...
Chryfi's user avatar
  • 129
0 votes
1 answer
156 views

If we don't use function composition, does Maybe remain a monad?

A monad is a monoid in the category of endofuctors. Category is a set of two things: Set of elements Set of binary operations between these elements. When we talk about the category endofunctors we ...
pro100tom's user avatar
  • 449
50 votes
7 answers
11k views

Why is inheritance bad in a Person-Student model?

I've just started learning about Inheritance vs Composition and it's kind of tricky for me to get my head around it for some reason. I have these classes: Person class Person { public string Name {...
Octavian Niculescu's user avatar
4 votes
5 answers
2k views

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

I was reading about composition over inheritance and came across a question about solving the Circle-Ellipse Problem in Object-Oriented Programming. This kind of problem is often used as an example of ...
drkvogel's user avatar
  • 157
5 votes
3 answers
254 views

UML Composition parent association end

The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent (association). However, shouldn't ...
Aldan Creo's user avatar
1 vote
1 answer
738 views

UML Composition parent multiplicity

The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent. However, given that: a ...
Aldan Creo's user avatar
0 votes
2 answers
645 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 ...
pro100tom's user avatar
  • 449
5 votes
2 answers
1k views

Design classes to model 3D scanned faces of ancient Greek/Roman sculptures: is multiple inheritance a good design solution?

I would like to deepen the topic of multiple inheritance using Python and I usually find examples that are too simple. I love art and I imagined the following problem and I want to understand if ...
blunova's user avatar
  • 398

15 30 50 per page
1
2 3 4 5
12