Set WeberTrivia.com to be my default homepage.   Suggest a Question                                               

Suggest A Question : :  Frequently Asked Questions : :  Search : :  Relevant Manuals : : 
PHP Questions : :  Linux Questions : :  MySQL Questions : : 
home  [ Login ] 

Initialization

Initialization -- Creating a Log object

There are three possible methods to create a Log object. You can create a Log_ object directly or call either the &singleton() or the factory() method of the Log class.

Directly initializing an instance of the Log is probably the easiest method to understand.

The second two approaches make use of software engineering design patterns (the "factory" and "singleton" metaphors).

Specifically, calling the factory() method will create a new instance of one of the Log_ subclasses. The type of subclass that is returned is specified by the first parameter (log_type) passed to the factory() method. This approach effectively hides the subclasses while still allowing the programmer to request a concrete instance of a certain subclass. This is useful in cases where the subclass type needs to be chosen at runtime.

The factory() method must always be called using PHP's static method notation - Log::factory.

The singleton() method is identical to the factory() method except that it guarantees that only a single instance of the requested Log_ subclass exists. The singleton() method bases each instance's uniqueness on the parameters used in the instance's creation. In other words, only one instance with a given set of creation parameters will ever be returned by the singleton() method. The second invocation will simply return a reference to the existing instance.

The singleton() method must also be called statically. In addition, it requires PHP's reference notation - &Log::singleton.

Who's Online
Guest Users: 5
Google
Web
WeberTrivia
WeberDev
WeberForums
 Free Sample Chapters  Free Sample Chapters
  Deliver First Class Web Sites: 101 Essential Checklists
Want to learn how to make your web sites usable and accessible? Want to ensure that your sites meet current best practice, without spending hours trawling through incomprehensible specifications and recommendations from dozens of different books, research papers, and web sites? Want to make sure that the sites you build are "right the first time," requiring no costly redevelopments?

More Sample Chapters

PHP General