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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:44:31+00:00 2026-06-06T14:44:31+00:00

I helped design and implement and Droid API written in PHP. Though it works

  • 0

I helped design and implement and Droid API written in PHP. Though it works just fine, I am always looking to refactor my code.

Is it ok to have objects within other objects that have a common ancestor?

This may be an elementary question, but I can’t seem to find information to support whether or not this is poor practice.

The goal is to have class foo provide common constants and methods to all.

Example:

            abstract class foo {
             //constants
             //common methods to all
            }

            class bar extends foo{
             //represents something
            }

            class widget extends foo {
             //represents something else
            }

            class controller extends foo{
                //controls flow
                public function __construct(){
                    $this->my_bar= new bar();
                    $this->my_widget= new widget();
             }
            }

Classes bar and widget may not need to extend foo, but methods within those objects wouldn’t know about the common things that foo knows without sending parameters.

There seems to be too much redundancy going on, just looking for a best-practice.

  • 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-06T14:44:32+00:00Added an answer on June 6, 2026 at 2:44 pm

    Creating a framework requires lots and lots of tries that will make you fall and then get back up on your feet.

    The most important thing about your question is to make sure you dont fall into the trap that the Liskov substitution principle describres:

    “If it quacks like a duck and looks like a duck but need batteries, it
    could be a duck but it probably isn’t.”

    The Liskov principle is simple, make sure that when you extend
    something, you are not changing the contract of the class. If a class
    used to return something on a function and you extend it to return
    something radically different, how will the user know how to adapt?
    You are defeating the purpose of reusability because you are providing
    a class that identifies as the base class it extends, but it doesn’t
    behave like the base class with added functionnalities.

    What i suggest the most is that you always try to make your class hierarchy as realistic as possible but remember the SOLID principle at all times. For more information on SOLID, look at my blog at:

    http://crazycoders.net/2012/03/confoo-2012-make-your-project-solid/

    Good luck

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

Sidebar

Related Questions

simonn helped me to code an ordered integer partition function here. He posted two
Hi someone helped me write some of this code last night through another question:
Now that I was helped getting AJAX running just great, I'm having problems running
I have just been helped on a problem I have here . var win
I've tried all sorts of design approaches to solve this problem, but I just
I'm relatively new using OOP in PHP. It's helped immensely in the organization and
This is another design pattern in some legacy code that I couldn't find much
I am trying to implement my first WPF application using an MVVM design pattern.
I'm developing an App using Google's UI design guidelines, so I want to implement
I have a question regarding the best design pattern for code reuse when dealing

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.