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 7865833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:12:21+00:00 2026-06-03T00:12:21+00:00

I need some design suggestions for an Image class hierarchy. Currently, I have 2

  • 0

I need some design suggestions for an Image class hierarchy.
Currently, I have 2 types of images (one is a standard image, the second doesn’t contain standard image data).
Sometimes I want the object to allocate the memory for the image data, and other times I just want it to point to it.

The problem arises when I want to give TypeA images specific functionality.
If TypeA images inherit from Image, I will have to duplicate the functionality of the Allocated vs. non-Allocated Image.

I’m sure there is a better way to do this, I remember some elegant solutions with mixins during university, but can’t find a way to use that here.

My current design looks like:

class Image
{
public:
Image(int width, int height, int bpp);
virtual ~Image() {};
    // getters

    template <typename T>                                  
    T* ptr() { return reinterpret_cast<T*>(m_imageData); } // T depends on bpp

 protected:
    // metadata
    char* m_imageData;
};

class AllocImage : public Image
{
public:
    AllocImage(int width, int height, int bpp, DataType dataType) :
        Image(width, height, bpp, dataType)
    {
        m_imageData = new char[m_dataSize];
    }

    ~AllocImage()
    {
        delete m_imageData;
    }
};

class ImageHolder : public Image
{
public:
    ImageHolder(int width, int height, int bpp, DataType m_dataType);

    void setPtr(const void* ptr);
};

class AllocatedImageTypeA : public AllocImage
{
public:
    // Type A specific methods
};

class NonAllocatedImageTypeA : public ImageHolder
{
public:
    // duplicated Type A specific methods
};
  • 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-03T00:12:22+00:00Added an answer on June 3, 2026 at 12:12 am

    If all the differences are constrained to how the image is held (allocated or not), you could use the policy model.

    The short explanation is that you would pass a policy object to the image, where the policy describes whether you need to deallocate the image or not, how to access it, etc., basically anything that relates to the differences that arise from how the image data is held (allocated vs. pointed). Then all your access to the image will be through the policy.

    For example, instead of writing

    delete image;
    

    You would write:

    policy.del(image);
    

    Where policy.del can be a delegate to delete or a no-op, depending on the actual type of the policy (that is in line with what the image requires)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I need some suggestions in the database design schema I've created below... I am
I need some advice about the design on my app. I have several screens
We need some input on what is a good design pattern on using AJAX
I need some resources that talk about how to design your software to be
I'm doing some design/debugging in IRB and need to login a user and then
I'm considering a design for a private messaging system and I need some input
I'm looking to a design a protocol for a client-server application and need some
Isn't there a Design Pattern who describes how to high cohesion? I need some
There is a pretty strong need for us to design some workflows around various

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.