Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:24:32+00:00 2026-06-18T04:24:32+00:00

I’ve got a library written in C++ that provides a Virtual Machine (VM) of

  • 0

I’ve got a library written in C++ that provides a Virtual Machine (“VM”) of a graphical programming language. It uses an image (e.g. png file) as its source code and executes instructions. The VM is used in different types of applications (console, gui) so the aim for the lib is to be as flexible as it can be.

The question is: what should be the relation between the VM and the image object? Should it be aggregation (VM constructor takes existing Image instance as a parameter) or composition (VM constructor takes image file path as string parameter)?

Composition is where the outside (VM) object cannot exist without the inside object (image). Well, in this case a VM can exist, but it’s useless without any image (can’t perform no instructions if there is no code). So it should take the string parameter and create and destroy the image object on its own. But how about validating the string filepath (check if there’s no image there OR the file is not an image OR the image binary is corrupted) – where should this validation be implemented? The VM constructor, I guess?

On the second hand, if the VM could replace one image with another, it could be aggregation (more like Java Virtual Machine). But I’m not sure if it’s a good approach – VM would have to reset all image pointers and data stack bound to the image. Maybe one VM per one image is a cleaner and more logical solution.

Would you choose aggregation or composition in this case? Thanks for your answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:24:33+00:00Added an answer on June 18, 2026 at 4:24 am

    Here’s steps to decide between aggregation and composition:

    1. If you cannot handle several objects with dependencies, use composition.
    2. If you can handle several objects, decision should be based on whether your image is inside or outside of VM object. If you consider it inside VM, use composition. If you consider it outside of it, use aggregation.

    Note that handling several objects (with aggregation) is quite difficult. Usually requires something like:

    struct Env {
       std::vector<I*> v1;
       std::vector<I2*> v2;
    };
    int push_image() { v1.push_back(new Image); return v1.size()-1; }
    int push_vm(int image_id) 
        { v2.push_back(new VM(v1[image_id])); return v2.size()-1; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.