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
0
votes
1 answer

Composing object in javascript by passing a list of functionality to a factory function

Using an example from this source const barker = (state) => ({ bark: () => console.log('Woof, I am ' + state.name) }) const driver = (state) => ({ drive: () => state.position = state.position + state.speed }) const murderRobotDog = (name) =>…
Peter S.
  • 315
  • 2
  • 14
0
votes
0 answers

Object composition pattern example

I am learning JS and have came across an interesting article about object composition pattern in JS. What I am wondering in this code: let Magic = (superclass) => class extends superclass { shout() { if (super.shout) super.shout(); …
Leff
  • 1,968
  • 24
  • 97
  • 201
0
votes
0 answers

Determine the container class of an object in Python 3

Class1 is instantiated in Class2 as follows. Class2 also contains another variable, say: class Class2: class1 = Class1() a = 0 I want to create a method myDef() in Class1 that can read or write to a. How do I access a from within myDef()…
sm535
  • 587
  • 7
  • 20
0
votes
0 answers

Overloaded Composition Object Instantiation and Usage Questions

I'm feeling a little confused regarding C++ Composition with overloaded constructors. I have read these other articles here, here, and here but still feel like my question is a little different from those. The first one was the most helpful and I…
0
votes
1 answer

Can I exactly mimic inheritance behavior with delegation by composition in Python?

In python, I want to mimic the following behavior with delegation by composition: class Object1(object): def __init__(self): pass def method1(self): print "This is method 1 from object 1" return self.method2() …
Charlee
  • 23
  • 4
0
votes
1 answer

C# Multiple abstract class composition design

I'm preparing in Monogame a little game engine, where I would want to have something like gameObject composed from DrawableObject And ClickHandler(i.e: public class GameObject : DrawableObject, ClickHandler Problem is - C# doesn't support multiple…
bartexsz
  • 239
  • 1
  • 11
0
votes
2 answers

Calling constructor after object Definition

class first{ int fa,fb; public: first(); first(int x,int y); void display(); }; first::first():fa(0),fb(0){ } first::first(int x,int y):fa(x),fb(y){ } void first::display(){ cout<
Getsuga
  • 13
  • 4
0
votes
1 answer

Make object accessible in inherited method in golang

I am trying to implement inheritence in golang. Below is example: type A struct { Number int } type B struct{ A name String } func (a A) GetNumber() { // Here I want to use instance of B fmt.Println(a) // but this is giving me…
Paritosh Singh
  • 6,288
  • 5
  • 37
  • 56
0
votes
1 answer

Avoiding instanceof when polymorphism can't be used

I have multiple classes generated from XSD files using XJC. These classes are automatically generated as part of the build process and therefore can't be modified. The classes share a common structure. I have client code that needs to use these…
manash
  • 6,985
  • 12
  • 65
  • 125
0
votes
1 answer

How Can I Export a Factory and/or its Method in MEF 2?

I am looking into MEF 2 (Microsoft.Composition) and am looking to integrate it with my existing code base. My current codebase has an IFactory interface with a simple signature: public interface IFactory { T Create(); } I would like to…
Mike-E
  • 2,477
  • 3
  • 22
  • 34
0
votes
1 answer

ReferenceClasses and object composition in R

I want to do basic object composition in R and I'm facing this simple problem. I have 2 R5 classes, "Lambda" and "Composition". The class "Composition" has an attribute of class "Lambda". Class "Composition" can't be created:".Object$initialize(...)…
0
votes
2 answers

Swift Inheritance / Object Structure

Define the following complex object hierarchy below into a playground in XCode: class Foo { var name: String required init(name: String) { self.name = name } } class Bar: Foo { } class Baz: Bar { } Creating instances of these…
RRP
  • 328
  • 8
  • 11
0
votes
0 answers

Is there an easy way to compose an object from other objects?

Is there an easy way to compose an object based on other objects? i am thinking the solution lies using DI container & Interfaces eg. public IObjectA : IObjectB, IObjectC {...} public ObjectA CreateObjectA() { ObjectB b = new ObjectB(); ObjectC c…
0
votes
2 answers

What is the logic of composition in object oriented design?

I am confused about the composition (has a) relationship. It is clear to me that for example a car class has a motor class. My problem is about classes they do not own another class logically, but own them physically in order to use them. You have…
lulijeta
  • 900
  • 1
  • 9
  • 19
0
votes
1 answer

Compositional approach to build an application with Angular

How to connect angular controllers using data from HTML code? I have a server-side framework, which allows me to build an application by connecting components together. Some of these components get transformed into a bit of HTML markup. Other…