The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
1answer
92 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 ...
1
vote
1answer
187 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
76 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 ...
1
vote
1answer
45 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 ...
1
vote
1answer
82 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
65 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
32 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: ...
0
votes
1answer
74 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 ...
1
vote
1answer
56 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
161 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 ...
-1
votes
2answers
88 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 ...
1
vote
1answer
345 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 ...
2
votes
1answer
147 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
vote
2answers
120 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 ...
-1
votes
2answers
259 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 ...
1
vote
3answers
411 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 ...
4
votes
2answers
934 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 ...
0
votes
1answer
98 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 ...
2
votes
1answer
93 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
108 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 ...
3
votes
1answer
411 views

How to maintain encapsulation with composition in C++?

I am designing a class Master that is composed from multiple other classes, A, Base, C and D. These four classes have absolutely no use outside of Master and are meant to split up its functionality ...
3
votes
4answers
441 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
2answers
169 views

Visitor only applicable when using the Composite pattern?

For a long time I've tried to get my head wrapped around the visitor pattern, and somehow this thing keeps being rather fuzzy to me. I'm currently under the impression it is only useful to apply ...
1
vote
2answers
113 views

Inheritance vs 'specification' by fields

I'm currently reading 'Head first design patterns', and already the first chapter threw some questions towards me. This chapter introduces the 'prefer composition over inheritance' design principle, ...
1
vote
2answers
146 views

Alternatives to inheritance on complex structures?

I'm working on an ASP.NET Webforms project, using the MVP Pattern (which the presenters as you may know use a Page Controller pattern). I'm given a rather complex inheritance chain for my controllers. ...
4
votes
2answers
398 views

How to use the Decorator pattern to add little functionality to big objects?

This question regards the usage of the Decorator pattern to add little functionality to objects of large classes. Following the classic Decorator pattern, please consider the following class ...
3
votes
3answers
558 views

Why should one subclass instead of composite when using the Factory Method design pattern?

I'm currently learning about design patterns. I learned about the Factory Method pattern. This pattern means that in order to implement a factory to create objects, one should subclass the class that ...
1
vote
3answers
193 views

Does this in the Observer pattern count as composition?

In a classic implementation of the Observer design pattern, the subject has a list of references to all of it's observers, and each observer might have a reference to it's subject. Is this considered ...
6
votes
1answer
264 views

Is it fair to say that “macros don't compose”?

On this blog post aphyr (who is a brilliant programmer) states: Clojure macros come with some important restrictions. Because they’re expanded prior to evaluation, macros are invisible to ...
4
votes
1answer
401 views

Inheritance in test classes

I have an interface Serializer with methods serialize and isSerializerFor. I created a first implementation of this using TDD, and ended up with a nice clean test case fully covering a nice clean ...
4
votes
2answers
273 views

If an entity is composed, is it still a god object?

I am working on a system to configure hardware. Unfortunately, there is tons of variety in the hardware, which means there's a wide variety of capabilities and configurations depending on what ...
4
votes
2answers
214 views

Is excessive indirection and/or redundant encapsulation a recognized concept? [closed]

I'm curious if there's a series of tendencies or anti-patterns when programming whereby a developer will always locally re-wrap external dependencies when consuming them. A slightly less vague ...
1
vote
1answer
406 views

Internal exposure of implementation details on inheritance

I'm reading the "Effective Java" book which suggests to favor composition over inheritance. The example it gives shows something like this: public class InstrumentedHashSet<E> extends ...
8
votes
2answers
784 views

How do I avoid writing lots of pass-through functions in a wrapper?

I have a class, which wraps another class of a common base type. Because the base type interface is quite large this involves writing a lot of pass-through functions. I am looking for a way to avoid ...
7
votes
4answers
1k views

Looking for a real-world example illustrating that composition can be superior to inheritance

I watched a bunch of lectures on Clojure and functional programming by Rich Hickey as well as some of the SICP lectures, and I am sold on many concepts of functional programming. I incorporated some ...
3
votes
3answers
2k views

what does composition example vs aggregation

Composition and aggregation both are confusion to me. Does my code sample below indicate composition or aggregation? class A { public static function getData($id) { //something } ...
0
votes
5answers
2k views

Inheritance vs composition in this example

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): ...
3
votes
7answers
1k views

Inheritance using non-abstract base class

This post is based on the question http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance/11758048#comment15634305_11758048. Some people said - check whether there is “is-a” ...
3
votes
1answer
290 views

Is this Hybrid of Interface / Composition kosher?

I'm working on a project in which I'm considering using a hybrid of interfaces and composition as a single thing. What I mean by this is having a contain*ee* class be used as a front for ...
11
votes
2answers
2k views

When Rob Pike says “Go is about composition”, what exactly does he mean? [closed]

From Less is Exponentially More If C++ and Java are about type hierarchies and the taxonomy of types, Go is about composition.
3
votes
1answer
623 views

Composition vs. Inheritance [duplicate]

Here's what is given: public interface Request {} // there are 20 subclasses of Request public class CreateUserRequest implements Request { @NotEmpty public String userName; } // request ...
5
votes
2answers
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 ...
3
votes
6answers
1k views

What are the alternatives to “overriding a method” when using composition instead of inheritance?

If we should favor composition over inheritance, the data part of it is clear, at least for me. What I don't have a clear solution to is how overwriting methods, or simply implementing them if they ...
3
votes
2answers
1k views

OOP - Composition, Components and Composites Example?

I've been reading a bit about OOP in relation to Composition, Components and Composites. I believe I understand the fundamental principle (not sure). Can someone please provide a code example of a ...
0
votes
2answers
538 views

Is this bad design for a Shape interface?

I'm creating a vector editing program in C++, and I need a Shape interface which other concrete classes will implement. There is a requirement that no implementation inheritance is allowed. The design ...
36
votes
4answers
19k 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 ...
0
votes
2answers
277 views

Inheritance versus Composition in a business application

I have a training management and tracking system, with a high level structure as follows: We have a Role1, e.g. Manager, Shift-boss, miner, etc. and a Candidate, training for that Role. The role has ...
4
votes
1answer
545 views

Model independency in MVC and most efficient way to do method calls

TLDR: Are models supposed to be application-dependant and totally worthless when starting a new application, or are you supposed to design models independently so that they act as stand-alone ...
6
votes
3answers
225 views

How to design a system that allows for multiple parallel extensions of the same “component”?

As a player, I found the following problems about creating and using "extensions" (aka mods) for games: 1) Whenever the game is updated, all the mods break. 2) Most mods don't work with each ...