Questions tagged [object-composition]

Object composition is about making more complex objects by assembling simpler objects. Do not use this tag for function composition .

Object composition is one of the main mechanism in object oriented programming to combine simpler objects into more complex ones.

For more details, see:

Do not use this tag for:

100 questions
27
votes
8 answers

How to make python class support item assignment?

While looking over some code in Think Complexity, I noticed their Graph class assigning values to itself. I've copied a few important lines from that class and written an example class, ObjectChild, that fails at this behavior. class Graph(dict): …
Jack Stout
  • 1,265
  • 3
  • 12
  • 25
9
votes
1 answer

Android Room TypeConverter not working

I'm trying to save some data in my Room database but it keeps showhing me an error, here's the code: MovieDao.kt @Dao interface MoviesDao { @Query("SELECT * from movie") fun getAll() : LiveData> @Update fun update(movie:…
Rodrigo Costa
  • 93
  • 1
  • 4
9
votes
2 answers

Unique pointer and const correctness

I was not expecting this code to compile: #include #include class A { public: inline int get() const { return m_i; } inline void set(const int & i) { m_i = i; } private: int…
6
votes
2 answers

pandas: Composition for chained methods like .resample(), .rolling() etc

I would like to construct an extension of pandas.DataFrame — let's call it SPDF — which could do stuff above and beyond what a simple DataFrame can: import pandas as pd import numpy as np def to_spdf(func): """Transform generic output of…
Igor Pozdeev
  • 286
  • 2
  • 11
6
votes
1 answer

Objects composition of NEventStore components for DI

I'm adding NEventStore to my existing project and I'm using DI. I'd like to have an instance of CommonDomain.Persistence.EventStore.IRepository injected into my MVC controller. The only implementation of this interface is EventStoreRepository. This…
trailmax
  • 34,305
  • 22
  • 140
  • 234
6
votes
2 answers

Composing polymorphic objects in ASP.NET MVC3 project

The essence of my question is how to compose these objects (see below) in a sensible way with MVC3 and Ninject (though I am not sure DI should be playing a role in the solution). I can't disclose the real details of my project but here is an…
5
votes
5 answers

Object composition promotes code reuse. (T/F, why)

I'm studying for an exam and am trying to figure this question out. The specific question is "Inheritance and object composition both promote code reuse. (T/F)", but I believe I understand the inheritance portion of the question. I believe…
Andrew Rasmussen
  • 14,912
  • 10
  • 45
  • 81
5
votes
2 answers

Variadic Template Functor Call

So I've been trying to use variadic templates to compose objects out of more convenient subtypes, but I'm having trouble getting it to do exactly what I want. template struct SeqMethod:public Functor...{ template void…
violet_white
  • 404
  • 2
  • 15
5
votes
0 answers

Is using the __getattr__ method as a composition pattern good Python practice?

First - please accept my apologies if this is a duplicate - I have the feeling that I have seen some sort of similar discussion before, but I really cannot find it. My question regards object composition in Python that should look like inheritance…
cleros
  • 4,005
  • 1
  • 20
  • 30
5
votes
1 answer

Alternative PImpl Idiom - advantages vs disadvantages?

The traditional PImpl Idiom is like this: #include struct Blah { //public interface declarations private: struct Impl; std::unique_ptr impl; }; //in source implementation file: struct Blah::Impl { //private…
LB--
  • 2,506
  • 1
  • 38
  • 76
4
votes
1 answer

Refactor inheritance into composition keeping polymorphic capabilities in C++

I might run into a problem in the future and I will like to be well prepared for it today. The problem deals with inheritance, polymorphism and composition in a C++ context. How can we refactor "inheritance code reuse" into composition and still be…
The Marlboro Man
  • 971
  • 7
  • 22
4
votes
2 answers

Java - Why does ClassName.this.variable work when variable is static?

I'm trying to fully understand how does "this" work. In my previous post I understood why we use the "this" keyword. My understanding of static is that the class has one copy of that member. "this" is used to represent the current object. For all…
MdT
  • 871
  • 3
  • 10
  • 15
4
votes
2 answers

Redundant code in composition class C++

I'm trying to pick up C++. Everything was going well until my 'practice' program hit I very minor snag. That snag, I believe, stems from a design issue. Think of Blackjack(21). I made a few classes. Card Deck Hand Player A Deck consists of -…
3
votes
1 answer

Using Composition and Implementation in State Design Pattern

I read this link enter link description here, to learn State Desing Patern. interface class: public interface State { void doAction(); } onState class: public class TVStartState implements State { @Override public void doAction() { …
3
votes
1 answer

What are the practical differences between Mixins and Inheritance in Javascript?

Is just (simulating) multiple inheritance the only advantage of mixing: Object.assign( MyClassA.prototype, MyMixinB ) versus inheritance class MyClass extends MyClassB { // MyClassB = class version of MyMixinB in ES6 Javascript? Thanks
cibercitizen1
  • 20,944
  • 16
  • 72
  • 95
1
2 3 4 5 6 7