Skip navigation

Sign up | Lost password? | Help

Hello World

Practical programming... and stuff...

Posts tagged with "design patterns"

What are the controller and model in MVC?

,

A lot of people seem to be slightly confused about what the M and C, Model and Controller, of MVC are, in regards to web applications.

  • What does the Model do?
  • What does the Controller do?


View is what everyone seems to know, though… I wonder why is that so? What is so confusing about Models and Controllers?

Read the rest of the post at codeutopia.net

Singleton pattern vs Static classes

,

Why use Singleton over Static classes?
If you want a simple class that's accessible from everywhere in your code, you could easily use a static class to achieve this.

In PHP, you can use :: to access classes statically: MyClass::doSomething(), in C# you can declare a class static and so on. It's much simpler to create and access static classes than singleton classes, too.

The singleton does have some advantages though...

Read more...

Globals are evil

, ,

Globals are evil - do not use them. Quoting Martin Fowler,

remember that any global data is always guilty until proven innocent.



What is a global? A global is a variable that is accessible from anywhere in an application. For example, in PHP declaring any variable outside a function/class method will make it global.

But what about when I want to have some data globally available in my application?
One useful solution is to use the singleton pattern to create a storage class or something like that. We'll look at that later in this post.

Read more...

Design patterns: The Factory

, ,

In my post about the problems in Zend Framework implementation of the MVC pattern I briefly mentioned the factory design pattern and that it could be used to create a view factory.

In this post I'll explain the concept of the factory a bit further and provide an example view factory implementation for you. We also brush the singleton pattern a bit.

Read more...