The tag has no usage guidance.

learn more… | top users | synonyms

4
votes
5answers
315 views

Is “too much methods” a valid reason to break the “composition over inheritance” rule?

I usually prefer to follow "composition over inheritance" rule, until I start stepping in the world of Java GUI. In my experience, for adding custom requirements in a GUI components, for example, add ...
1
vote
1answer
45 views

Can composition be used in unit/integration testing over inheritance

In larger projects, there can often be a group of tests that test the functionality of related classes. These tests often share a lot of setup and preparation functionality. What happens then is ...
4
votes
5answers
642 views

Understanding UML composition better

The difference between Composition and Aggregation in UML (and sometimes in programming too) is that with Composition, the lifetime of the objects composing the composite (e.g. an engine and a ...
1
vote
1answer
155 views

Should we “prefer composition over multiple interface”?

Should we avoid multiple interface if possible? Because I think at most cases a class with multiple interfaces can be replaced with another version with composition and single interface only e.g.: ...
2
votes
2answers
127 views

Java: Composition of classes implementing same interface

Let's consider an example wherein I have to model the following: Class to schedule exams for a Student, lets call it StudentExamScheduler Class to schedule exam for a Class. Let's call it ...
0
votes
1answer
167 views

Should I force “composition over inheritance” rule to class members?

As I know, according to "composition over inheritance" rule, we should avoid reuse a method by inheritance, but how about class members? Suppose I have parent and child classes: public class Animal{ ...
7
votes
4answers
2k views

Is dependency injection by hand a better alternative to composition and polymorphism?

First, I'm an entry level programmer; In fact, I'm finishing an A.S. degree with a final capstone project over the summer. In my new job, when there isn't some project for me to do (they're waiting ...
2
votes
2answers
40 views

Composition of Data Transfer Objects

Let's say I want to create a shop/order system. I'll have an Order DTO to which I'll map the data from a request and results from the database. The object will consist of an order number, a customer ...
0
votes
1answer
68 views

Separate interfaces for dependency data providers?

I am attempting to refactor a component of a large project, which currently has a lot of dependencies to global state of the project environment. The goal (for my taste) is a "SOLID" architecture, ...
2
votes
1answer
74 views

Term for the opposite of the functional Compose operator

In functional programming, given a function f and a function g we can define a function . (compose): let (.) f g = fun x -> g (f x) Is there a term for the function which applies arguments in the ...
4
votes
2answers
112 views

Applying composition over inheritance to Vehicle classes

I have a car maintenance garage program that has an abstract Vehicle class that has several derived classes like Car MotorCycle, etc. Each of those derived vehicles in turn is either a fuel or an ...
3
votes
5answers
205 views

What is the correct OOP relation between complex and real numbers?

On one hand class complex { double real; double imaginary; } it is composition on the other hand class complex : double { double imaginary; } it is inheritance Which one is ...
46
votes
9answers
8k views

Code Smell: Inheritance Abuse [duplicate]

It's been generally accepted in the OO community that one should "favor composition over inheritance". On the other hand, inheritance does provide both polymorphism and a straightforward, terse way of ...
6
votes
1answer
113 views

How to allow for custom Rules in a Entity Component System designed game engine?

So I've been doing a lot of research into game engines, and Entity Component System (ECS) seems to be the most flexible and extendable design to use. Just to summarize, in ECS the basic idea is that ...
3
votes
6answers
318 views

Can we say “If a parent class never appears in my codes except in its child class, it should be composition instead of inheritance”?

I read some posts about "composition over inheritance","where to use composition/inheritance" , "Is-a relationship..." or "Liskov substitution principle" for some time, but I am not sure if I get the ...
2
votes
1answer
126 views

Are nested private classes considered composition?

Background I am considering a design that includes a public API class containing many nested private classes. I am doing this for the following reasons: Why private nesting? They will have no use ...
1
vote
1answer
115 views

Is this a misuse of “composition over inheritance”?

The general sentiment seems to be that composition is preferable, in most cases, over inheritance, as it leads to less coupling. But for a case like this, module Publishable def new? @content....
2
votes
2answers
151 views

Acceptable design to use public member objects in composition?

Say I have a large class called Root, which has a lot of members & functions: class Root { public: void func1(); // operates on a and b void func2(); ... private: A a; ...
36
votes
5answers
2k views

How is defining that a method can be overridden a stronger commitment than defining that a method can be called?

From : http://www.artima.com/lejava/articles/designprinciples4.html Erich Gamma: I still think it's true even after ten years. Inheritance is a cool way to change behavior. But we know that it's ...
5
votes
3answers
471 views

Composition over inheritance but

I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to ...
3
votes
1answer
385 views

Does Having DI Happen in the Composition Root go against the whole point of Dependency Injection?

I am using Dependency Injection for a .NET MVC web application in which I have three basic layers: 1) Web App 2) Service Layer 3) Data Layer I inject the data layer into the service layer and the ...
2
votes
5answers
2k views

How do inheritance and composition differ?

I'm wondering about the differences between inheritance and composition examined with concrete code relevant arguments. In particular my example was: Inheritance: class Do: def do(self): ...
56
votes
4answers
32k views

Why should I prefer composition over inheritance?

I always read that composition is to be preferred over inheritance. A blog post on unlike minds, for example, advocates using composition over inheritance, but I can't see how polymorphism is achieved....
1
vote
1answer
96 views

What is the difference between embedding and composing?

What is the difference between go's type embedding and object composition? My understanding is that type embedding is object composition except the methods of the embedded type are automatically ...
10
votes
5answers
549 views

Should I prefer composition or inheritance in this scenario?

Consider an interface: interface IWaveGenerator { SoundWave GenerateWave(double frequency, double lengthInSeconds); } This interface is implemented by a number of classes which generate waves ...
31
votes
2answers
1k views

What is the meaning of “doesn't compose”?

I see a lot of texts, especially functional programming texts, claim that certain CS concepts "don't compose". Examples are: locks don't compose, monads don't compose. I've been having a hard time ...
9
votes
4answers
761 views

Reducing boilerplate in class that implements interfaces through composition

I have a class: A that is a composite of a number of smaller classes, B, Cand D. B, C, and D implement interfaces IB, IC, and ID respectively. Since A supports all the functionality of B, C and D, A ...
1
vote
1answer
123 views

Ideal export in terms of size for asynchronous module definitions in JavaScript?

When creating AMD modules you can export whatever you like whether it be an object or a function. I vaguely recall reading a recommendation somewhere to export just one thing; the idea being "keep it ...
2
votes
4answers
444 views

“Imprinting” as a language feature?

Idea I had this idea for a language feature that I think would be useful, does anyone know of a language that implements something like this? The idea is that besides inheritance a class can also ...
5
votes
2answers
609 views

Is it possible to refactor inheritance to composition when virtual methods are called inside the base class?

Let's say I have a class called Country and two subclasses called AI and Player. The Country class has a number of virtual methods to allow player-specific or AI-specific behavior. I want to make it ...
2
votes
1answer
93 views

How minor of a case is a class appropriate for?

I'm trying to use composition in an Entity class of mine. So far, an Entity "is" Displayable(inherited an ABC), and "has" a Position(contains a point-like class). I know I will want my Entity to "have"...
1
vote
1answer
245 views

Inheritance or Composition?

Let's say I have a main class A and another class B. In the B class the user can change some settings and variables of the program that belongs to A, I want to be able to apply these changes to the A ...
3
votes
1answer
115 views

Do conditional delegation or different member types break the Composite pattern?

Here's how I understand the composite pattern: In the composite pattern, a root object is composed of objects which may be further composed. Moreover, to be considered composite, all those objects ...
2
votes
1answer
159 views

Language support for (syntactic) delegation in Java

Composition over inheritance is an old trend or even accepted state of the art in object oriented programming. It would be even easier to use in Java, if there were language support for delegation. ...
0
votes
1answer
203 views

refactor by inheritance or composition for large class that depend on common state [duplicate]

I have a huge class (>1000 lines), in which all methods depend on a small set of attributes in that class. I can think of 2 quick ways of refactoring. I keep it as a huge object, but split related ...
0
votes
1answer
42 views

Scoping template variables in “has-a” (compositional) relationships

I'm developing a new templating language for PHP, and one of the features is an object-oriented approach to nested child templates. For example, I can declare an object of type HtmlBuilder like this: ...
3
votes
1answer
178 views

Compose nested EventEmitters elegantly

I am developing a server-side JavaScript tool, and trying to do so in a modular way. I have a Parser class that is an EventEmitter - you call parse and it will eventually emit data and end events. It ...
2
votes
2answers
634 views

Design pattern for composition workflows

Please bear with me as I find this tricky to articulate exactly what I am after (probably not a good sign..). I have several services set up which can be combined in a particular order to create ...
2
votes
1answer
208 views

Should I use composition or inheritance for sharing configuration items?

I'm working on a fairly new project where I'd like to share some config items used by a JavaScript plugin. Specifically, the project is using jQuery dataTables and I want to find a good way of sharing ...
-1
votes
2answers
138 views

what is the difference between inclusion and inheritance [duplicate]

the question is self explanatory, I just want to know when to use the inclusion and when to use inheritance, and which one serves for re-usability. in other words, which one meets the Object ...
4
votes
1answer
1k views

Inheritance, Composition and Protocols

I'm reading a book on general object oriented concepts to try and gain a solid understanding of everything. One thing that is throwing me off is the difference between Inheritance and Composition. I ...
1
vote
2answers
313 views

Is composition and aggregation really a type of association relationship?

From Wikipedia: There are four different types of association: bi-directional, uni-directional, Aggregation (includes Composition aggregation) and Reflexive. From what I know: Composition ...
6
votes
6answers
1k views

What is the actual reason that locks (sentinels) in OO are hard to reason about? [closed]

In this talk, Rich Hickey introduces Clojure. He gives an Ants demo and talks about his motivations for implementing a Software Transactional Memory (STM) system. His reasoning for STM is that "...
3
votes
2answers
4k views

Why is inheritance generally viewed as a bad thing by OOP proponents [duplicate]

I keep hearing the phrase "Favour Composition over Inheritance" from GoF which is being annoyingly mentioned repeatedly by my friend who thinks it is a valid blanket statement but is it not more ...
12
votes
9answers
2k views

Should a developer know the inner workings of the computers' hardware? [closed]

I'm not talking just how memory is assigned and memory management (things that you can learn from C for example) but rather the hardware aspect and how each component of the computer hardware works ...
0
votes
1answer
206 views

In UML is it correct to have an association class with a composition or aggregation relationship?

An example of an association class is given here: http://pic.dhe.ibm.com/infocenter/rsarthlp/v9/index.jsp?topic=%2Fcom.ibm.xtools.modeler.doc%2Ftopics%2Fcassnclss.html Composition and Aggregation ...
1
vote
3answers
1k views

Extending a struct. Using helper classes rather than composition

I have a struct which I want to add static methods to. Yes, you guessed right I'm talking about Datetime. It's a pretty typical requirement to add MyCustomParse. It happens to return Datetime?, so it'...
4
votes
2answers
1k views

How to replace inheritance with composition in this case?

I've recently read several articles about the advantages of the composition over inheritance. Their authors said that you can always replace inheritance with composition (to be precise, they say they ...
2
votes
1answer
105 views

Testing complex compositions

I have a rather large collection of classes which check and mutate a given data structure. They can be composed via the composition pattern into arbitrarily complex tree-like structures. The final ...
0
votes
0answers
147 views

does class reference itself static anti pattern in prism

I have an application and my desing approach look like this: class Manager { public int State; static Manager _instance = null; public static Manager Instance { get { return ...