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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:34:55+00:00 2026-05-24T22:34:55+00:00

I have a base object (form_field_base) that is extended/inherited by other objects in the

  • 0

I have a base object (form_field_base) that is extended/inherited by other objects in the form of:

class form_field_base {
    // Lots of code
}
class form_field_text extends form_field_base {
    // Lots of code
}
class form_field_email extends form_field_text {
    // Extending the text object to update validation, and set input type="email"
}
class form_field_file extends form_field_base {
    // Lots of code, for example uploading files
}

The “form_field_base” provides helper methods that all of the form field types use, for example a html() function calls the specific object (form_field_email::html_input) to get the field, then put that in a string with the standard tag, etc.

All of these objects are used by many projects.

However, this latest project I’m working on requires the “form_field_base” object to be customised to allow the setting of some help text, a feature that no other project requires, and if future projects do, it will probably be done differently.

So how should this have be organised?

Ideally I won’t have a complete copy of “form_field_base”, as that would cause code duplication.

And it does seem like quite a bit of overhead to have dummy intermediate objects:

class form_field_base_common {
    // Lots of code
}
class form_field_base extends form_field_base_common {
    // By default is empty
}

class form_field_text_common extends form_field_base {
    // Lots of code
}
class form_field_text extends form_field_text_common {
    // ...
}

class form_field_email_common extends form_field_text {
    // Extending the text object to update validation, and set input type="email"
}
class form_field_email extends form_field_email_common {
    // ...
}

class form_field_file_common extends form_field_base {
    // Lots of code, for example uploading files
}
class form_field_file extends form_field_file_common {
    // ...
}

Taking that each one has it’s own file, which is auto-loaded (either a from a project specific location, if it exists, or from a common folder that all projects can access)… that is already 8 files that need to be found, opened, parsed, etc, just for supporting a form.

Surly there has to be a better way?

  • 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-24T22:34:56+00:00Added an answer on May 24, 2026 at 10:34 pm

    You have your inheritance chain and you want to modify the base implementation on a per project base while still keeping the common code and types (and not being forced to severely modify the existing projects).

    The way to go is to decouple the common functionality from project specific customizations. Use the decorator pattern which even enables you to share customizations between projects.

    You situation is for all existing projects:

    A <- B <- C
    
    A->a()
    B->a(), B->b()
    C->a(), C->b(), C->c()
    

    Your new project (lets say project 1) shall have:

    A1 <- B <- C
    
    A1->a(), A1->a1(),
    B->a(), B->a1(), B->b()
    C->a(), C->a1(), C->b(), C->c()
    

    The decorator pattern requires you to create a decorator for each object you want to extend (A1, B1, C1). You want the custom methods of A1 also available in your decorating B1 and C1, so you need to chain them the same way as the original classes.

    A1 decorates A
    B1 decorates B
    C1 decorates C
    
    A1 <- B1 <- C1
    
    A1->a1()
    B1->a1()
    C1->a1()
    

    You still want the functionality of A, B, C also in your decorating classes, so you need to create a link between each decorator and its decorating source class and delegate the appropriate methods:

    A1 hosts a reference of A
    B1 hosts a reference of B
    C1 hosts a reference of C
    
    A1->a() ----> $this->myA->a();
    B1->a() ----> $this->myB->a();
    B1->b() ----> $this->myB->b();
    

    All custom project 1 methods are executed directly:

    A1->a1() ----> $this->a1();
    

    In your new project 1 you use then:

    A1 instead of A
    B1 instead of B
    C1 instead of C
    

    Your A1, B1 and C1 may be allowed to create their instances of A, B, C right in their constructor although you could pass the instances to enable multiple decorations. In that case you will need proper interfaces, lets say IA, IB, IC. Then your A1 could have the method setA(IA theA) where theA might be an exact A or even an A1 or A2 or A3 … But this is more advanced and you will find more information by googling the decorator pattern and you perhaps need a little bit of experience with interfaces and polymorphy.


    Altogether:

    1. Leave your inheritance chain as it is

    2. Create a decorator chain for each custom project

    3. Link the decorators to their original class and delegate the common functionality.

    4. Use the decorators instead of the original classes in your custom project. They are now identical to their originals plus have the additional methods you want to add.

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

Sidebar

Related Questions

Assume some domain and view objects (that have no common base class) public class
I have an inherited code base that was developed in .NET 1.1. When I
I have a custom Form I've made that extends the Doctrine base forms for
I have a base class object array into which I have typecasted many different
I have an object that is mapped to a cookie as a serialized base-64
I want to have a base class which dictates the alignment of the objects
Okay I have a series of objects based on a base class which are
Say I have a couple of basic objects like so: [Serializable] public class Base
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have a UserControl that takes a class object as property DataSource. On DataBind,

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.