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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:30:49+00:00 2026-05-13T23:30:49+00:00

I have read a lot of articles on developing classes (I am using php),

  • 0

I have read a lot of articles on developing classes (I am using php), with the tag lines :
‘scalable, robust, maintainable and extensible’.

But as a beginner, I have been creating classes that are, in my words, “just abstracted”. Meaning I just separated a bunch or repetitive codes and put them in a class and provide methods for accessing common tasks.

The thing is, I can’t find a way to make my class extensible (I know the concept of abstract classes and such, I am even using them, but just to define methods that my other classes will follow). The thing is, I always find myself editing the core class just to add functionlities.

Any tips on making my class extensible? (I have googled on this and everything that pops out are explanations of abstract classes, interfaces and OOP, no discussions on pointers or some tips for making extensible classses).

Oh, btw, go easy on me, I have started “actual” oop programming 9 mos ago (the university I’m from had me going on theories on OOP, but they had us working PROCEDURALLY, because it’s faster and it meets damn project deadlines, and that went on for 4 years until I graduated).

  • 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-13T23:30:50+00:00Added an answer on May 13, 2026 at 11:30 pm

    You should check out the book Design Patterns: Elements of Reusable Object-Oriented Software

    The problem with making extensible classes, as you’ve discovered, is decomposing the system into useful and reusable objects.

    The task is difficult because many factors come into play: encapsulation, granularity, dependency, flexibility, performance, evolution, reusability, and on and on.

    Are you trying to model some real world scenario, or are you focusing on communication / collaboration and dependencies inside your application?

    Here’s an example that I think kinda demonstrates what you are looking for. There are certainly a far more, far better examples:

    I wanted to develop a caching system that offered my developers a simple, normalized API no matter what / where they were caching something. What do I want in a caching system (at the basic level)?

    • I want to be able to cache something (set)
    • I want to be able to retrieve that something (get)
    • I want to be able to invalidate the cache (delete)

    I came up with this:

    abstract class MyNs_Cache
    {
        abstract public function Set($key, $data, $ttl);
        abstract public function Get($key);
        abstract public function Delete($key, $ttl);
    }
    

    There’s my extensible base class. I’ve then got three caching classes MyNs_Cache_Fs, MyNs_Cache_Apc and MyNs_Cache_Memcache

    class MyNs_Cache_Fs
    {
         ...
    
        public function Set($key, $data, $ttl)
        {
            // here I use fopen/fwrite/etc. to create the cached data
        }
    
        public function Get($key)
        {
            // here I retrieve the file from the filesystem (if it exists)
        }
    
        public function Delete($key) { ... }
     }
    

    That’s fairly straight forward. It implements the cache in terms of a FileSystem. It doesn’t offer anything past my original class.

    class MyNs_Cache_Apc
    {
        ...
    
        public function Set($key, $data, $ttl)
        {
            return apc_add($key, $data, $ttl); // NOT A FILESYSTEM CALL
        }
    
        public function Get($key) { ... } // you get the idea.
    
        // This is specific to APC, so I add the functionality HERE
        // NOT in my main Caching class.
        public function PurgeCache()
        {
            return apc_clear_cache();
        }
    }
    

    My APC cache does everything I want in a caching system (set/get/delete) but it also offers the ability to clear the entire cache (something that’s not useful for my FileSystem cache and impossible with memcached)

    class MyNs_Cache_Memcache
    {
        // Memcached needs a pool of servers. APC and filesystem don't.
        private $servers = array(..);
    
        // It also uses a memcached object.
        private $conn;
    
        public function __construct()
        {
            $this->conn = new Memcached;
    
            foreach ($this->$servers as $server)
                $this->AddServer($server);
        }
        ...  // we do all the standard stuff using memcached methods
    
        // We also want to be able to manage our connection pool
        public function AddServer($server)
        {
            $this->conn->addServer(...);
        }
    
        // And in some cases, we use inc/dec from memcached
        // APC doesn't have this, and it makes little sense in a filesystem
        public function Increment($key) { ... }
    }
    

    Now I know that I can always get one of my cache objects and just in with $obj->Get(‘some_key’) and I’ll always get a result.

    Likewise, I also have access to functionality specific to what I’m currently trying to work with.

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

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Entity Framework designer is terrible - I've had the… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If by "hijack" you meant sniff the packets then what… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If you want two actions to be atomic, embed them… May 14, 2026 at 5:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.