[wp-trac] [WordPress Trac] #22958: Add object-oriented foundations and design patterns

WordPress Trac noreply at wordpress.org
Sun Dec 16 00:40:33 UTC 2012


#22958: Add object-oriented foundations and design patterns
-----------------------------+-----------------------------
 Reporter:  npetetin         |       Type:  feature request
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  General
  Version:                   |   Severity:  normal
 Keywords:                   |
-----------------------------+-----------------------------
 Since the last releases, more and more classes have been introduced as
 part of core WordPress, which makes it de facto more and more object-
 oriented. However, more advanced object-oriented paradigms are still
 missing. Among those paradigms: polymorphism (open/closed principle) and
 design patterns.

 Introducing an object factory instead of the use of "new" statements would
 allow extending core and plugin classes by simple polymorphism and then
 creating tons of new extension opportunities that go far beyond the
 current action/filter model (which would remain great and useful) by
 facilitating the process of writing object-oriented plugins.

 In order to stick to the WordPress way, the design patterns to be
 implemented should be:
 * Generic Factory: the class name and the construction arguments would be
 passed as arguments
 * Static Proxy: even if the factory itself would be an object, it would be
 accessed through a normal and classical function

 The Singleton design pattern would also be a natural and useful addition.

 Here attached is a proposed implementation for this new API. To make it
 short and sweet, the basic services offered would be:
 * Register a class: set the class name and the class file, as well as the
 class it’s optionally a substitute of by extension
 * Register an object: set the unique name and polymorphic class of a
 singleton that may be called later
 * Get a registered object: provide with the named singleton created from
 the right registered class
 * Create an object: provide with a new object created from the right
 registered class

 Such an object-oriented foundation might also be the first stone of a
 fully object-oriented WordPress in the future, who knows...

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22958>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list