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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:10:57+00:00 2026-06-06T20:10:57+00:00

I have a State class that includes configuration as well as some state-specific methods.

  • 0

I have a State class that includes configuration as well as some state-specific methods. I also have a Factory class that I inhertit my MVC classes from that also has a reference to this State object. This makes sure that all of my MVC objects have specific State-related functionality. For example, my State class includes methods for setting and reading cache or sessions.

My Factory class has a number of methods that are simply wrappers, like this:

public function myFunction($data){
    $this->State->myFunction($data);
}

The idea is that these methods are defined in Factory, but are actually executed by State object. This allows me to call:
$this->myFunction(); rather than the longer one that includes State in it, when writing code.

I don’t know enough about how PHP works internally, but is this efficient? My thought process has been that since I usually only have one instance of State object, then having method wrappers in my Factory class is better, because otherwise those methods would include a lot of code that is not used most of the time. But I am not sure how PHP works internally.

At times I can have dozen objects that have the parent Factory class and all of them reference the same State object. Is it efficient to have wrapper methods defined in Factory that simply call methods of State, rather than deal with State directly? Or am I just adding additional overhead to the whole system?

My idea was that if Factory is simply a class that is inherited and includes wrappers for a lot of functionality, then I can streamline development more efficiently. Does it save memory if the class that you inherit from has wrappers as opposed to fully defined code in methods?

  • 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-06T20:10:58+00:00Added an answer on June 6, 2026 at 8:10 pm

    No, such wrapper has not performance benefit. Actually, what you get this was is an extremely minor loss of performance.

    What’s more important, this way you are hiding dependencies, which might make it harder to maintain the code.


    Few thoughts on your topic

    I get the impression, that you are doing it all wrong tm. Here are the issues, that I have with what you wrote in the question:

    • Is the State class responsible for configuration OR “state specific methods”?

      There is such thing as SRP, which states, that every class should have a single responsibility. You could also say, that every class should have only one season to change.

    • Why do your “MVC classes” inherit from Factory class?

      In object oriented code, the keyword extends represents an is-a relationship between classes. It’s OK to have class Oak extends Tree, but when you write class User extends Table, it is complete insanity .. and kinda insulting. This is covered by LSP (for a simplified explanation: look here).

    • You have misunderstood the purpose of Factory pattern.

      Factory is a creational pattern. This means, that the purpose of factories is to return object instances. Instead of inheriting some methods, which provide access to State instance, you should inject it in each of created structure.

      class Factory
      {
          protected $state = null;
      
          public function __construct( $state )
          {
              $this->state = $state;
          }
      
          public function create( $name )
          {
              $instance = new $name( $this->state );
              return $instance;
          }
      }
      

      This will have the added benefit that all the structures, which Factory instance created, share the same State instance.

    • Seems like you are trying to have global state thought-out your codebase

      If every in your application need access to instance of State, then something is deeply wrong with the whole architecture. You end up with situation where a single object exists in all layers, thus causing a major leak in abstractions. You basically are just hiding a global variable.

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

Sidebar

Related Questions

I have a State class that is fully implemented as outlined below. I also
I have a class that has a method: -(NSInteger) getCityCountForState:(NSString *)state CityArray:(NSMutableArray *)cityArray {
I have a GUI tool that manages state sequences. One component is a class
I have a class State that has a string data type called moveType .
I have state data in a txt file that I used to seed my
basically i have (state, state code) pairs, that are subsets of country [USA] ->
I have a Client and ProposalRequest model that look like this: class Client <
I have to use a GUI Element that draws a picture at a specific
I'm using Delphi 2007 Pro. I have a runtime package that includes a number
Let's state a few facts upfront: Livedocs tells us that dynamic classes enable us

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.