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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:17:21+00:00 2026-05-12T12:17:21+00:00

Over the past few years I’ve been on projects where we’ve run into a

  • 0

Over the past few years I’ve been on projects where we’ve run into a similar problem in our object hierarchy that always seems to cause problems. I was curious if anyone here knew of a classical OOP (Java, C#, PHP5, etc) design pattern that could gracefully handle this situation.

Say we have an existing system. This system has, among other things, two types of entities, each modeled with an individual class. Let’s say

  1. Customer

  2. SalesRepresentative

For historical reasons, neither of these classes inherit from the same base class or share a common interface.

The problem I’ve seen is, inevitably, a new feature gets specced out that requires us to treat the Customer and the SalesRepresentative as the same type of Object. The way I’ve seen this handled in the past is to create a new class that includes a member variable for both, and then each method will operate on the objects differently depending on which is set

//pseudo PHPish code
class Participator
{
    public $customer;
    public $salesRepresentative;

    public function __construct($object)
    {
        if(object is instance of Customer)
        {
            $this->customer = $object;
        }

        if(object is instance of SalesRepresentative)
        {
            $this->salesRepresentative = $object;
        }           
    }

    public function doesSomething()
    {

        if($customer)
        {
            //We're a customer, do customer specific stuff
        }
        else if($salesRepresentative)
        {
            //We're a salesRepresentative, do sales 
            //representative specific stuff
        }           
    }
}

Is there a more graceful way of handling this type of situation?

  • 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-05-12T12:17:21+00:00Added an answer on May 12, 2026 at 12:17 pm

    Maybe a Wrapper can be used here. Create a Wrapper Interface say ParticipatorWrapper that specifies the new functionality and build concrete Wrappers for each class, say CustomerWrapper and SalesRepresentativeWrapper that both implement the new functionality.

    Then simply wrap the object in its appropriate wrapper and write code that targets the ParticipatorWrapper.

    Update: Javaish code:

    interface ParticipatorWrapper{
        public void doSomething();
    }
    
    class CustomerWrapper implements ParticipatorWrapper{
        Customer customer;
        public void doSomething(){
           //do something with the customer
        }
    }
    
    class SaleREpresentativeWrapper implements ParticipatorWrapper{
        SaleRepresentative salesRepresentative;
        public void doSomething(){
           //do something with the salesRepresentative
        }
    
    }
    
    class ClientOfWrapper{
        public void mymethod(){
             ParticipatorWrapper p = new ParticipatorWrapper(new Customer());
             p.doSomething();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been getting into Ruby over the past few months, but one thing that
Over the past few years I've had to delve deeper into Spring's source. I've
I've noticed in two different projects over the past few days that distances aren't
I run an arcade site and over the past few years it's had many
Over the past few days I have been trying to create/run a project in
Over the past few years I've changed from having a long flowing page of
Over the past few weeks it seems like I've been interrupted by maintenance tasks
There have been several questions over the past few days about the proper use
I've been asking a question or two over the past few days of working
I have just started learning NHibernate. Over the past few months I have been

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.