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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:50:55+00:00 2026-05-26T01:50:55+00:00

My code is located here: https://github.com/maniator/SmallFry Should I make it so that that the

  • 0

My code is located here: https://github.com/maniator/SmallFry

Should I make it so that that the App class does not have to use static functions but at the same time be able to set and set variables for the app from anywhere?

Or should I keep it how it is now with App::get and App::set methods?

What are the advantages and disadvantages of both?
How would I accomplish that 1st task if I was to undertake it?

Related Question

Sample code:

//DEFAULT TEMPLATE
App::set('APP_NAME', 'SmallVC');
//END DEFAULT TEMPLAT
//
//DEFAULT TEMPLATE
App::set('DEFAULT_TEMPLATE', 'default');
//END DEFAULT TEMPLATE

//DEFAULT TITLE
App::set('DEFAULT_TITLE', 'Small-VC');
//END DEFAULT TITLE

//LOGIN SEED
App::set('LOGIN_SEED', "lijfg98u5;jfd7hyf");
//END LOGIN SEED

App::set('DEFAULT_CONTROLLER', 'AppController');

       if(App::get('view')){
            $template_file = $cwd.'/../view/'.App::get('view').'/'.App::get('method').'.stp';
            if(is_file($template_file)){
                include $template_file;
            }
            else {
                include $cwd.'/../view/missingview.stp'; //no such view error
            }
        }
        else {
            App::set('template', 'blank');
            include $cwd.'/../view/missingfunction.stp'; //no such function error
        }
  • 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-26T01:50:55+00:00Added an answer on May 26, 2026 at 1:50 am

    I think you have a feeling that static is bad. What I am posting may seem fairly crazy as it is a massive change. At the very least hopefully it presents a different idea of the world.

    Miško Hevery wrote static methods are a death to testability.

    I like testing, so for that reason I don’t use them. So, how else can we solve the problem? I like to solve it using what I think is a type of dependency injection. Martin Fowler has a good but complicated article on it here.

    For each object at construction I pass the objects that are required for them to operate. From your code I would make AppController become:

    class AppController
    {
      protected $setup;
    
      public function __construct(array $setup = array())
      {
         $setup += array('App' => NULL, 'Database' => NULL);
    
         if (!$setup['App'] instanceof App)
         {
             if (NULL !== $setup['App'])
             {
                 throw new InvalidArgumentException('Not an App.');
             }
             $setup['App'] = new App();
         }
    
         // Same for Database.
    
         // Avoid doing any more in the constructor if possible.
    
         $this->setup = $setup;
      }
    
       public function otherFunction()
       {
          echo $this->setup['App']->get('view');
       }
    }
    

    The dependancies default to values that are most likely (your default constructions in the if statements). So, normally you don’t need to pass a setup. However, when you are testing or want different functionality you can pass in mocks or different classes (that derive from the right base class). You can use interfaces as an option too.

    Edit The more pure form of dependency injection involves further change. It requires that you pass always pass required objects rather than letting the class default one when the object isn’t passed. I have been through a similar change in my codebase of +20K LOC. Having implemented it, I see many benefits to going the whole way. Objects encapsulation is greatly improved. It makes you feel like you have real objects rather than every bit of code relying on something else.

    Throwing exceptions when you don’t inject all of the dependencies causes you to fix things quickly. With a good system wide exception handler set with set_exception_handler in some bootstrap code you will easily see your exceptions and can fix each one quickly. The code then becomes simpler in the AppController with the check in the constructor becoming:

         if (!$setup['App'] instanceof App)
         {
            throw new InvalidArgumentException('Not an App.');
         }
    

    With every class you then write all objects would be constructed upon initialisation. Also, with each construction of an object you would pass down the dependencies that are required (or let the default ones you provide) be instantiated. (You will notice when you forget to do this because you will have to rewrite your code to take out dependencies before you can test it.)

    It seems like a lot of work, but the classes reflect the real world closer and testing becomes a breeze. You can also see the dependencies you have in your code easily in the constructor.

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

Sidebar

Related Questions

I'm using the android version of cocos2d located here: https://github.com/ZhouWeikuan/cocos2d I'm an iPhone guy
I'm running this sample code located here: http://monoclestudios.com/cocos2d_whitepaper.html using cocos 2d-iphone 0.7.2, and the
I followed the official docs on https setup located here: https://help.ubuntu.com/6.06/ubuntu/serverguide/C/httpd.html#https-configuration I had to
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code that is untestable really annoys me. The following things make oo-code untestable: global
I'm experimenting with TreeView plug-in located here: http://docs.jquery.com/Plugins/Treeview One of the options it has
I have code located here http://jsfiddle.net/jostster/5XAUb/ This works in Safari / FF (for the
Where is the code for the terminal command 'tee' located in Mac OS? [Added]
I need to know what is code compiled unit in .net. It s located
Code below is not working as expected to detect if it is in design

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.