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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:46+00:00 2026-06-10T05:34:46+00:00

Let’s say you have abstract class A doing some stuff. Then you have abstract

  • 0

Let’s say you have abstract class A doing some stuff. Then you have abstract class B doing other stuff.

And lastly a few normal classes, let’s say C … Z.

Both A and B provide functionality that are used by class C .. Z classes. In my case mainly an observer pattern which is static, and some __get magic + lazy-loading for a certain type of properties – this is not static. I’m thinking to merge this into one class, but then I’m sure it violates SRP 🙂

So I am extending A, B in C, D etc… Essentially all C .. Z classes inherit the functionality of the A & B classes. So besides what they are supposed to do, they also do the observer stuff and so on

Does this violate the single-responsability principle?

  • 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-10T05:34:47+00:00Added an answer on June 10, 2026 at 5:34 am

    I don’t know if this applies to your specific case, but I find that most of the time, an abstract class and its implementation can be split into two normal classes.

    For example:

    abstract class AbstractAdder {
        int AddThree(int a) {
            Add(a, 3);
        }
    
        abstract int Add(int a, int b);
    }
    
    class NormalAdder inherits AbstractAdder {
        int Add(int a, int b) {
            return a + b;
        }
    }
    
    var result = new NormalAdder().AddThree(6);
    

    Can be changed into:

    class ThreeAdder {
        ThreeAdder(IGenericAdder genericAdder) {
            this.genericAdder = genericAdder;
        }
    
        int AddThree(int a) {
            return this.genericAdder.Add(a, 3);
        }
    }
    
    class NormalAdder implements IGenericAdder {
        int Add(int a, int b) {
            return a + b;
        }
    }
    
    var result = new ThreeAdder(new NormalAdder()).AddThree(6);
    

    This has several advantages:

    • The classes are less tightly coupled, because they don’t inherit from each other. Because the classes are separate, the responsibilities are more separate and well-defined.
    • You can use functionality of multiple classes, whereas you can only inherit from one abstract class. (Edit: apparently not in PHP because you have multiple inheritance)
    • It is clearer (IMHO) on which class the method is called.

    It seems like you are using inheritance to couple multiple classes, but that is not what inheritance is meant for.

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

Sidebar

Related Questions

Let's say we have the following: abstract class A; class B : public A;
Let me explain best with an example. Say you have node class that can
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say you have a class, with certain properties, and that you tried your
Let's say I have 2 windows in my application, and two classes responsible for
Let's say I want to have some kind of a cache that did something
Let's say we have: @Entity public class Order { @Id private int id; @OneToMany(mappedBy=order)

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.