Tagged Questions

The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
1answer
76 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
votes
0answers
24 views

Javascript component (de)composition [duplicate]

I am currently in the process of building a distributed application, containing mobile devices, a backend/server and webclients with javascript, using MQTT as event bus. When researching the ...
1
vote
1answer
95 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
64 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
143 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
190 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
877 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
65 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
88 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
76 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
301 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
343 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
135 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
95 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
136 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. ...
3
votes
2answers
202 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
243 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
162 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
226 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
279 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
253 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
180 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
292 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
568 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 ...
6
votes
4answers
894 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
1k 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
985 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
285 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
585 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 ...
3
votes
6answers
859 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
492 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 ...
33
votes
4answers
14k 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
252 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
497 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
217 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 ...
41
votes
9answers
4k views

What is the most orthogonal programming language?

I find myself repeatedly annoyed by having to teach freshmen about special language rules (like array-to-pointer decay) that have absolutely nothing to do with programming in itself. So I wondered: ...
3
votes
1answer
349 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 ...
9
votes
5answers
1k views

How do we know to favour composition over generalisation is always the right choice?

Whether an object physically exists or not, we can choose to model it in different ways. We could arbitarily use generalisation or composition in many cases. However, the GoF principle of "favour ...
75
votes
14answers
20k views

Where does this concept of “favor composition over inheritance” come from?

In the last few months, the mantra "favor composition over inheritance" seems to have sprung up out of nowhere and become almost some sort of meme within the programming community. And every time I ...
5
votes
1answer
389 views

Architectural Composition Languages

Recently stumbled upon this paper (PDF) talking about ACLs, or Architectural Composition Languages. They're a fusion of two earlier lines of research: Architectural Definition Languages (such as UML) ...
0
votes
5answers
2k views

Why does the use of interface-based programming appear to be limited to behaviour?

I have been doing a little thinking about inheritance vs. realization vs. composition. I am not about to post the whole detail here. So I was wondering, when we are not talking about creating ...
11
votes
9answers
981 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 ...
11
votes
6answers
321 views

How do I get a feeling for visual design as a programmer?

Over the last years of web programming, I've noticed how bad I am at designing things. I have substantial knowledge of HTML and CSS, I can make a website look like I want it to, I have some pretty ...
36
votes
9answers
4k 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 ...