Questions tagged [composition]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-2
votes
1answer
27 views

Calculating position of menu options with variable sizes

Not entirely sure if this is the most appropriate community for this but... I'm looking for solutions to calculate positions for menu options when the amount of options vary and when each options ...
0
votes
1answer
75 views

Extension of classes - Where to put behaviour - How much direct-access is allowed

At this point i would exclude the inheritance.... So the question is about more like extend into a seperate class or into the class which should be extended, both play in the composition-league. So ...
1
vote
2answers
35 views

What does this statement about implementing forwarding methods of components mean?

I can't wrap my head around this statement here: One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be ...
0
votes
1answer
149 views

favor composition over inheritance: practical problems

In a C# application, I've got a behaviour that I would like to be available in different classes that not necessarily share the same ancestor. What better opportunity to 'favour composition over ...
1
vote
1answer
50 views

Is this form generator a valid Composite GoF?

Searching for a good PHP real world example, I've found this example of "composite" using: FormElement as Component Fieldset and Form as Containers Input as Leaf (this is my UML from the code): ...
0
votes
0answers
32 views

Design choices for federated contribution and consumption of workflow steps

Currently we have 5 different workflow steps and the number of those steps are growing and they are being built by different teams. There are multiple use cases for us to combine those steps in ...
1
vote
2answers
69 views

Composite Design Pattern with unequal weightage

You have a video game in which upon killing final boss you get coins that get distributed based on whether you are: Person(individual) Group(consists of individuals or groups) If reward for killing ...
0
votes
2answers
176 views

Example of NOT associative (not composable) function

Bartosz Milewski, in his book "Category Theory for Programmers" says that: Composition is associative. If you have three morphisms, f, g, and h, that can be composed (that is, their objects match ...
1
vote
3answers
273 views

what it means when someone says - “statements/instructions are not composable”?

I have been using c# and trying to learn FP. In context of FP I often hear that usage of basic assignment or return statements are not considered composable, hence their usage is not advised in FP ...
18
votes
11answers
10k views

Need Good OOP Design For World and Countries Problem

I am currently working on problem with a chicken or egg first situation. Basically, I am designing a solution which goes like this: World is a collection of countries; Each Country has a name, flag ...
7
votes
2answers
486 views

Why are impure functions said to be non-composable?

I understand what pure functions are and when someone says pure functions are composable - I believe it means that the output of one function can be passed as an input to another function but same ...
4
votes
1answer
384 views

Delegate vs Forwarding in Java OOP

I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source: https://en.wikipedia.org/wiki/...
2
votes
3answers
837 views

Interfaces in Python, multiple inheritance vs. a home-made solution

I am writing a Python framework. In order to ensure a class has some properties, I make base "interface" classes like: class BananaContainer: def __init__(self): self._bananas = [] @...
0
votes
2answers
62 views

Modelling 2 composition relationships between 2 XML elements using UML

I want to model an XML schema that has the following composition relationships: A can contain B, and in another case B can contain A. Using a bi-directional composition is not an option here as it is ...
1
vote
1answer
90 views

Structuring a pipe for function composition when an intermediate result is needed by later functions

I have a set of pure functions that can be composed almost trivially in a pipe as initialValue -> [f] -> [g] -> [h] -> ... -> [m] -> [n] -> [o] -> outputValue The problem I ...
0
votes
1answer
292 views

Avoid too much dependencies for a Use Case in a Clean Architecture app

Context I'm currently developing an application following the Clean Architecture principles (at least I'm trying really hard to follow these). All my Dependency Injections are done manually, without ...
1
vote
1answer
176 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
1
vote
3answers
95 views

Applying Composition Over Inheritance to Page objects

I'm trying to figure out how to apply composition over inheritance to a system I'm building, and tripping up when I try to apply it to my page objects. The relevant objects are: PageFactory Page ...
9
votes
9answers
839 views

Inheritance vs Composition For Chess Pieces

A quick search of this stackexchange shows that in general composition is generally considered more flexible than inheritance but as always it depends on the project etc and there are times when ...
0
votes
1answer
380 views

DDD & composition

I have a project to build, which has the following requirements: topup a wallet by paying money in exchange for credit; this has also the constraint of needing an approval from the finance team, if ...
1
vote
4answers
242 views

Unit Testing order with contained & inherited objects

I'm confused about unit testing order. Many posts in StackOverflow say that unit test should be independent and small. IMHO, in the case of aggregation or composition, the member objects should be ...
0
votes
1answer
73 views

Inheritance or composition for a more advanced implementation of a class?

So i have a class called VirtualMouse, it is used to perform mouse actions such as moving and clicking. public class VirtualMouse { public VirtualMouse() { } public void ...
4
votes
3answers
3k views

How to reach the parent object?

I have a parent object that has some other objects as fields. The parent object fully owns these fields: they can be declared as fields of the parent object (MyPart part), directly, not as references. ...
1
vote
2answers
148 views

Composition - legal class diagram

I wanted to ask if this is a valid class diagram: I tend to think not, because it forces a certain wheel to belong to two vehicles at the same time (because of the 1 multiplicity). If the ...
2
votes
1answer
43 views

Decomposition by “role” or by “usage” - is that a thing?

I have a mail_queue table that is written to by web requests then worked on by a worker to send the mails. I've now had a moment of enlightenment re. what I was not comfortable with in the design. ...
-1
votes
1answer
74 views

How to model parent/child composite when the child is related to another class

I don't know which is the correct way to model this requirement in OOD: A device has many properties, each property has exactly one device parent. There are a set of procedures and a specific ...
4
votes
2answers
853 views

Does composition increase or decrease the coupling

We know that composition is a synonym of loose coupling. From here I read coupling becomes stronger between the classes A and B when: A has an attribute that refers to (is of type) B. To ...
0
votes
3answers
83 views

Abstract responsibility from caller without introducing complexity

I have two classes: public class Child { public List<Vector2> localPoints; public List<Vector2> localEdges; } public class Parent { public List<Child> children; ...
2
votes
6answers
1k views

Should I still prefer composition over inheritance if the child classes need BOTH the parent interface AND its class properties?

According to Why should I prefer composition over inheritance?, I should prefer composition over inheritance. But what if I need to access the interface and class member in generic way? For example, I ...
1
vote
4answers
7k views

Why the industry prefer/use composition over inheritance? [duplicate]

I was having a discussion with few friends about inheritance and composition and what I learnt from that discussion is that the use of inheritance more or less condemned in industry nowadays and ...
0
votes
0answers
26 views

How to organize classes which should reflect different versions of standard?

I have some standard which changes in time. Let's say I have std_v1, std_v2 and std_v3. Those standards have a lot of common parts with some little differences, possible additions and deletions. On ...
1
vote
3answers
224 views

Strategy Pattern and inheriting boilerplate functionality

I've read that when using the Strategy Pattern, you should stick to composition rather than inheritance. But does this mean that any inheritance at all is bad practice? If there is functionality to be ...
0
votes
2answers
122 views

Version checking when reading deeply nested structures

I need to open a game save file, read it, maybe modify it and then save it. The structure of the save is quite simple: it is an object with some members, some of which are data, while others are ...
37
votes
3answers
10k views

Is “composition over inheritance” violating “dry principle”?

For example, consider I have a class for other classes to extend: public class LoginPage { public String userId; public String session; public boolean checkSessionValid() { } } and ...
4
votes
2answers
150 views

Composition and calling part methods

What is the right concept of calling methods of parts in composition? I have a class class Body{ Arm arm; } class Arm{ public void waveArm(){} Finger finger } class Finger{ public void ...
2
votes
2answers
171 views

Is Chaining of Composition the right approach?

I'm working on some code where the structure looks like: Class A { Client client; B b; void process(request) { data = fetchData(client, data); b.process(data); } } class B { C c; ...
3
votes
1answer
210 views

To inherit or to override?

Imagine that I am writing a game where tanks fight with each other. A generic Tank class is created and has the method fire() which fires a cannon, looks like this Tank::fire() { /* fires a cannon */ ...
0
votes
1answer
59 views

How to represent self-composed implementations in inheritance hierarchies

Background: My company is working with camera systems. In the beginning we built our application around different models/setups of them, which i.e. consisted of different cameras or procedures to ...
6
votes
2answers
651 views

OOP without Inheritance [closed]

I'm making a language, and I'm considering disallowing inheritance. To be clear, this means: class A {} //Valid interface B{} //Valid class A2 extends A {} //Invalid class B2 implements B {} //...
-1
votes
1answer
102 views

What would be the best option in this scenario?

I have a statement. I know the ups and downs of both Composition and Inheritance, but I am unable to realize that what would be the best option the given scenario. SCENARIO: A Software company is ...
0
votes
1answer
259 views

Convenience vs Decoupling/Composition

Let's say I have a small CD burning library written in Python, with a CD class and a Burner interface + implementation classes: # Module cd.py class CD: def __init__(self): self.folders = [] ...
13
votes
8answers
4k views

“Prefer composition over inheritance” - Is the only reason to defend against signature changes?

This page advocates composition over inheritance with the following argument (rephrased it in my words): A change in the signature of a method of the superclass (which hasn't been overridden in ...
2
votes
4answers
1k views

Composition over Inheritance, why not both?

I have this out of context scenario, where what I think is good practices leaves me in a situation of both implementing an interface, and using composition to do the implementation. Imagine the ...
3
votes
2answers
315 views

Should I nest repositories like Russian dolls?

tl;dr Can I have a repository depend on another repository, where they both implement the same interface? I am working on a website analytics system that involves getting data from different sources. ...
2
votes
1answer
753 views

Dependecy Injection and Composition Root

Just recently started to grasp on MVC and design patterns. (back to school at 34 ;) ) I was asked by my teacher to design a two part application. It's a recipe website that as an admin WinForms app. ...
10
votes
1answer
679 views

Is there a situation where it would be better to use weak references instead of simple composition?

Although the Java docs specify, that Weak references are primarily for canonicalizing mappings, you will find many, many, many people on the internet stating, that the WeakHashMap is perfect for ...
4
votes
2answers
626 views

Java8: why two composition methods: andThen and compose?

As a beginner in both java8 and functional programming, I think I'm missing something when reading about function composition since I cannot find a reason why there are two methods that do this, ...
4
votes
2answers
149 views

Would you use object proxy, extend the class, if else conditions or make a duplicate class for supporting two different API's?

This is not an easy one but here goes. I'm working on adapting a JavaScript project (ACE Editor) to support two different targets but maybe more. Any way I look at it, it looks like a large task and ...
4
votes
5answers
549 views

Should I encapsulate an object inside another object as methods or just access it directly?

Suppose I have a class A: public class A{ public void a(){ } } and class B use A: public class B{ private A a; } Should I encapsulate A in B: public class B{ private A a; ...
7
votes
3answers
373 views

Composition of two classes with common inheritance root

Hope your day is going well. I want to make the following composition of two objects with the same inheritance root: There will be 3 basic operations on the Wallet class: add, getCards and ...