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

  • SEARCH
  • Home
  • 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 8988515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:01:24+00:00 2026-06-15T22:01:24+00:00

Is the following a good design pattern in C++? Pet PetOwner | | ———

  • 0

Is the following a good design pattern in C++?

    Pet               PetOwner
     |                   |
 ---------         --------------
 |       |         |            |
Cat     Dog     CatOwner     DogOwner

In other words, two accompanying class hierarchies. Have you seen this done, and is it considered a good practice?

Let me clarify further. This design certainly follows the “open-closed” principle. It is “open” in the sense that new things can be added easily (new Horse and HorseOwner subclasses), and it is “closed” in the sense that new things can be added without modifying existing code.

The purpose of these two accompanying hierarchies is that, for example, PetOwner has a feed() virtual function, and Pet has a make_hungry_sound() virtual function. Also, Cat is constructed with a particular CatOwner.

Is there a better design pattern that can replace two related hierarchies like these? The reason I’m asking is that I’m wondering whether it’s considered a good practice to require people to add two classes at the same time when extending things. Seems a bit dubious…

  • 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-15T22:01:24+00:00Added an answer on June 15, 2026 at 10:01 pm

    Seems like a highly subjective question. Answers can be many (and more if you add more info to the question) so I’ll just comment based on what’s available in the question:

    Assuming the PetOwner has more to do than just feed(), yes, it’s justified to have it. E.g. you won’t breed every pet, you won’t put every pet in a beauty contest.
    If all PetOwner has to do is feed, just one concrete class is enough.

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

Sidebar

Related Questions

I am following the presentation model design pattern suggested by Martin Fowler for my
I think the following might be a good fit for the Strategy pattern but
I have a winforms application and I'm not following any kind of design pattern.
I've been trying to come up with a good design pattern for mapping data
Are there any good resources (books, authoritative guides, etc.) for design patterns or other
Following the good jQuery Plugins/Authoring instructions I have a little question (function($){ // Default
The following page looks good in Firefox, Safari, Chrome, IE6 and IE8... but it
I'm using with good results the following code to access alla of my php
Just wondering if the following is considered to be good programming practice or not?
How might one craft a good explanation of why the following code is not

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.