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
2
votes
2 answers

Aggregate shapes to new shape in OpenCV

I'm trying to detect an object composed of other objects. Actualy, there are three circles in my binary image which shape up a triangle as shown here: These circles are correctly detected, but only as single objects as shown here: What I need to…
Roberto
  • 713
  • 8
  • 14
2
votes
2 answers

What is a better way? Downcasting? Interface? Abstract class?

All, I have to be doing this wrong. It seemed like a good idea at the time but as I get deeper into it, I think there is a more proper programmatic way of going about it. Thus I ask you... One note. I'm using Google AppEngine and the Datastore to…
2
votes
1 answer

Is it possible to use object composition in PL/SQL?

I'm trying to figure out how to implement object composition using pl/sql object types. Here is my super simple example. CREATE OR REPLACE TYPE PERSON FORCE AUTHID DEFINER UNDER MYSCHEMA.BASE_OBJECT ( student …
eikonomega
  • 1,971
  • 17
  • 28
2
votes
1 answer

c# object composition

I have a class called LetterRect with two of the fields being of type LetterSquare. For example: public class LetterRect : Microsoft.Xna.Framework.GameComponent { private LetterSquare square1; private LetterSquare…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
1
vote
1 answer

Object comparison inside and outside a class

I have two classes, the first class Movie has one attribute string name. The second class Festival has also one attribute Movie[] movies. The following method which I wrote inside of the class Festival checks if Movie mv exists in movies and returns…
Ariel Oz
  • 11
  • 2
1
vote
1 answer

C++ correct way of wrapping array of subobjects for my new object?

class myObject{ private: subOBJ* subList; int size public: myObject(subOBJ list[]); } For example, my object looks something like this and I want to create an object that will do something with an array of subOBJs passed…
tofokevin
  • 37
  • 5
1
vote
1 answer

What would be the pythonic way to implement a class that represents "a list with a title"?

I am trying to better understand composition vs inheritance in python so I have crafted a hopefully simple example. Suppose I want to implement a class TitledList that is intended to behave just like a standard list, but with an additional attribute…
thecommexokid
  • 303
  • 2
  • 13
1
vote
1 answer

what is the order of function overloading

I have a doubt on the result of the question below. When calling function f from main, the call goes to f(B &) although I have int operator overloaded and f(int) is defined first. If I comment out the f(B &) function, then the call goes to f(int)…
1
vote
2 answers

Why does Object.assign add to the prototype's constructor?

I am learning composition in Javascript and was wondering why Object.assign() in my code is adding methods to the prototype's constructor rather than the object's constructor. I will link the code below. Basically, the code is adding two methods…
Kaleb Meeks
  • 111
  • 1
  • 1
  • 9
1
vote
1 answer

Perl/OOP: How to create object of "Class B" in constructor of "Class A"

I have Class A with following constructor: sub new { my ($class, %args) = @_; return bless(\%args, $class); } I have another class, LWP::UserAgent, which I want to use in my Class A. I could solve the problem by doing this: ua =…
Nazar
  • 45
  • 4
1
vote
1 answer

Is there a way to auto generate a flatten pojo from a pojo with object composition

I need to store documents into Elasticsearch indexes and therefor I defined a mapping. From my java client I need to supply it with pojo's which looks like the Compony class. It has a lot of duplicated values. I could use object composition pattern…
Hakan54
  • 3,121
  • 1
  • 23
  • 37
1
vote
1 answer

JS Object composition via functions adding prototype functions

I have been fiddling around with object building via composition in Javascript (specifically NodeJS) and I have come up with a way of building up my objects but I need to know if this is an insane way of doing things. The simple version is this: I…
1
vote
0 answers

Learning object composition in javascript

I am still trying to get in my head the object fundamentals in javascript which seems to be quite different than classical paradigm. I have written a toy example to fetch weather data, the code is below: import axios from 'axios' const…
CodeYogi
  • 1,352
  • 1
  • 18
  • 41
1
vote
1 answer

Are Local Refernece varibles also called as Composition?

Java_Composition: A class can have references to objects of other classes as members. Question?: Should that be a Instance-variable of a class to call it as Composition Or it is also called as Composition, if it is a Local-variable ? Demo: Preceding…
1
vote
1 answer

Refactoring a huge Python class using Inheritance to do Composition

I built a pygame game a few years back. It worked, but wasn't the best coding style and had a lot of classic code smells. I've recently picked it back up and am trying to refactor it with more discipline this time. One big code smell was that I had…
RobertB
  • 1,879
  • 10
  • 17