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
1
vote
1 answer

Multiple Inheritance, using interface vs using composition in Java

Based on some stackoverflow post: Java does not support multiple inheritance. There are a few workarounds I can think of: The first is composition: make a class that takes those two activities as fields. The second is to use interfaces. // This is…
SHE
  • 121
  • 3
  • 11
1
vote
2 answers

Is it possible to use C++ object composition where choice of object is determined at run-time?

Say I have a class Face. I wish to use composition to build Face. Face has eyes, so I can create a class Eyes and use composition adding eyes to Face. But what if I subclass eyes, e.g. class Eyes { ... }; class BlueEyes : public Eyes { ... }; class…
PartialOrder
  • 2,870
  • 3
  • 36
  • 44
1
vote
1 answer

Error initializing pointer to vector using unordered_map value

I have a class called street_map that contains a map with int keys and values of type vector. In one of the methods, I am trying to initialize a pointer to the vector value to get its contents. class street_map { public: explicit…
Pat Myron
  • 4,437
  • 2
  • 20
  • 39
1
vote
4 answers

Difference between inheritance and composition

I have extracted following difference between inheritance and composition. I wanted to know what does delay of creation of back end object mean? Please find below difference. Composition allows you to delay the creation of back-end objects until…
1
vote
2 answers

C++ access private member in composition of two classes from base class

Since I'm a newbie in C++, here it goes! I have a base class (I'm not using inheritance anywhere) with two objects from two other classes. I need to have access from a private member to the other in another class. class base { private: myClass1…
waas1919
  • 2,365
  • 7
  • 44
  • 76
1
vote
2 answers

PL/SQL Object Composition: Problems With Object Instantiation/Constructor

This is a follow-up question to Is it possible to use object composition in PL/SQL? That question addressed how to create object types in PL/SQL which are mutually dependent (i.e. one attribute of each object is a reference to the other…
eikonomega
  • 1,971
  • 17
  • 28
1
vote
3 answers

Object composition - cannot access object properties

Hi i have a problem with object composition. The class CInvoice needs to have a CCustomer object inside, so I created a constructor that requires a customer. In Invoice.h file there is a line: CCustomer *customer; And the mentioned constructor…
BuahahaXD
  • 609
  • 2
  • 8
  • 24
0
votes
1 answer

Preventing broken object composition in REST

I have a Sinatra app with a Project model and a Task model, and a project has_many tasks. It's a composition type of relationship, meaning a project cannot exist without tasks associated. I create a project on /projects/new, then redirect to…
fullstackplus
  • 1,061
  • 3
  • 17
  • 31
0
votes
0 answers

CoreML model can not open generated model class

I dropped a CoreML model which is 3 layer FC simple model, whole XCode using OC. The model indicates like this: But I can not found. any instruction or arrow button to view this class What should I do?
Nicholas Jela
  • 2,540
  • 7
  • 24
  • 40
0
votes
2 answers

Passing functions from class to class ... How to maintain utility functionality and mixing it into objects?

I want to inherit all the methods from source classes into my main target class/function. I kind of did something, but I wonder if there are better or gentler ways to do this. The idea is that I can keep good readability and separate methods in…
0
votes
1 answer

TypeScript :: Inheritance issues

I have a base class implementing a bunch of methods, each returning a new reference to a copy of object to allow chaining. class Base { constructor(public name: string) {} funcA(): Base { return new Base('FUNC_A') } funcB(): Base { return new…
AweSIM
  • 1,651
  • 4
  • 18
  • 37
0
votes
1 answer

OOP Project - Beginner - looking for feedback

Hi I just finished a VERY Basic airline reservation system. Wanted some feedback please let me know what you all think, if I am obfuscating information or passing parameters where I shouldn't or if things don't make sense Airline Class: handles…
K.Veerina
  • 45
  • 4
0
votes
0 answers

Using Composition Over Inheritance Leads To Duplicated Code?

In my quest to make the best weapon system out there (currently working in UE4) I have been moving all of my code to components. public class Weapon { public FiringComponent firing; ... } public class FiringComponent { public void…
0
votes
2 answers

Proper API for access data members of container

I have the following class: class Document { public: Document(): // default values for members, // ... m_dirty{false}{} // Accessor functions template
user877329
  • 6,717
  • 8
  • 46
  • 88
0
votes
0 answers

Closure/Object Composition Investigation: Why is the first breakpoint hit only once while the breakpoint in closure scope is hit repeatedly?

Could use some feedback on a Saturday afternoon object composition/closure investigation (is it accurate, is it missing any key points, non-key points, can you help answer remaining questions/provide resources to do so). Thanks in advance :) run…