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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:32:50+00:00 2026-05-13T19:32:50+00:00

The gist of this question is about extending a class, minimizing jam-packing everything into

  • 0

The gist of this question is about extending a class, minimizing jam-packing everything into a single class, and maximizing code re-use. After reading this question, please feel free to edit the title or description to make it more succinct. Though the post looks long, I am just trying to be thorough by using a lot of examples.

Suppose I have a class:

class UsedByManyPeople
{
  // ...has many fields
};

As the name implies, this class is used by a lot of developers. I have to add 2 features to this class:

  1. a convert() that converts UsedByManyPeople to SomeOtherType
  2. a getFileName() that returns a string

Both of them are specific to my department’s needs.


First attempt solution

At first I thought about simply adding 2 new methods to UsedByManyPeople.Thus, the class will now look like:

class UsedByManyPeople
{
  // ...has many fields

  public:
    SomeOtherType const convert() const;
    std::string   const getFileName() const;
};

However, the 2 features are actually specific to my department’s use case, and other departments do not even have the class definition of SomeOtherType nor do they care about the getFileName().

Clearly, the above approach is not a good approach (?).

How would you extend this class?

Alternatives that came to my mind:


Subclass UsedByManyPeople and create my own class.

  • Tie data and method together

For example,

class ExtUsedByManyPeople : public UsedByManyPeople
{
  public:
    SomeOtherType const convert() const;
    std::string   const getFileName() const;
};

Create Helper classes, one for each method (yikes!), and implement it as static methods.

  • Separate data from methods, single class one responsibility

For example,

class UsedByManyPeopleToSomeOtherTypeConverter
{    
  public:
    static SomeOtherType const convert(UsedByManyPeople const&);
};
class UsedByManyPeopleFileName
{
  public:
    static std::string const getFileName(UsedByManyPeople const&);
};

Create a single Helper class, with all the methods inside.

  • Separate data from methods, single class many responsibilities

For example,

class UsedByManyPeopleHelper
{
  public:
    static SomeOtherType const convert(UsedByManyPeople const&);
    static std::string   const getFileName(UsedByManyPeople const&);
};
  • 1 1 Answer
  • 3 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-05-13T19:32:50+00:00Added an answer on May 13, 2026 at 7:32 pm

    Especially if the methods are specific to your departments use of the class you should implement them as in: Create a single Helper class, with all the methods inside.

    There are several reasons for this:

    • The single helper class can be
      located in another logical project
      structure
    • If your new methods don’t require access to the internal state of the class this is expressed clearly. It provides better encapsulation. (which you supplemented by const ref, which is think is a good style)
    • UsedByManyPeople shouldn’t
      be responsible for converting itself
      into another type. This violates
      SOLID
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a question about real code, it is just for discussion. It
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I've search through about 10 pages, can't find this question here. I'm trying to
The following gist: https://gist.github.com/1876791 (borrowed from the demo in this question ) is a
This question is about iOS device rotation and multiple controlled views in a UINavigationController.
Let me illustrate this question with code first: with Ada.Text_IO; procedure Test is task
I have a website (the basic gist of which is described in this question
Update: If you've just arrived at this question, the general gist is that I'm
Here's the gist of the code I am looking to incorporate error handling into.
This is related to another question I recently asked about storing a non-bare repository

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.