From 1f37ca385f7dd88663534e8e5103b124b429872e Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Tue, 23 Aug 2011 11:52:46 +0200 Subject: [PATCH 1/3] some more comments, typos etc. --- AbstractFactory/AbstractFactory.php | 8 ++++---- Adapter/Adapter.php | 2 +- Composite/Composite.php | 6 ++++-- Facade/Facade.php | 2 ++ Multiton/Multiton.php | 1 + Prototype/Prototype.php | 2 +- Singleton/Singleton.php | 4 ++-- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/AbstractFactory/AbstractFactory.php b/AbstractFactory/AbstractFactory.php index 2808f9f..ae4201a 100644 --- a/AbstractFactory/AbstractFactory.php +++ b/AbstractFactory/AbstractFactory.php @@ -10,10 +10,10 @@ namespace DesignPatterns; * usually the created classes all implement the same interface * * Examples: - * - A Factory to create media in a CMS: classes would be text, audio, video, picture - * - SQL Factory (types are all strings with SQL, but they vary in detail (tables, fields, etc.)) - * - Zend Framework: Zend_Form::createElement() creates form elements, but you could also call new T - * TextElement() instead + * - A factory to create media in a CMS: classes would be text, audio, video, picture + * - SQL factory (types are all strings with SQL, but they vary in detail (tables, fields, etc.)) + * - Zend Framework: Zend_Form::createElement() creates form elements, but you could also call + * new TextElement() instead * */ abstract class AbstractFactory diff --git a/Adapter/Adapter.php b/Adapter/Adapter.php index 0231bb8..3ecb4ed 100644 --- a/Adapter/Adapter.php +++ b/Adapter/Adapter.php @@ -12,7 +12,7 @@ namespace DesignPatterns; * Examples: * - different databases have the same interface to communicate although the underlying systems act differently * - * this is a VERY basic example which won't work at all + * this is a VERY basic example which won't work at all! */ interface DatabaseAdapter { diff --git a/Composite/Composite.php b/Composite/Composite.php index 65aca01..15e8340 100644 --- a/Composite/Composite.php +++ b/Composite/Composite.php @@ -6,11 +6,13 @@ namespace DesignPatterns; * composite pattern * * Purpose: - * to treat a group of objects the same way as a single instance of the object + * to treat a group of objects the same way as a single instance of the object, it establishes 1-to-n relationships + * between objects * * Example: * - a form class instance handles all its form elements like a single instance of the form, when render() is called, it - * subsequently runs trough all its child elements and calls render() on them + * subsequently runs trough all its child elements and calls render() on them + * - a class to process files would process it by running process on all row objects in the file * */ class Form diff --git a/Facade/Facade.php b/Facade/Facade.php index 46be4d4..60bfd7e 100644 --- a/Facade/Facade.php +++ b/Facade/Facade.php @@ -10,6 +10,8 @@ namespace DesignPatterns; * * Examples: * - Database Abstraction Layers + * - Doctrine2: EntityManager is the facade that one sees from the outside, but in there is much more going on, Unit of + * Work, etc. * */ class Facade diff --git a/Multiton/Multiton.php b/Multiton/Multiton.php index bd5adb8..4327a0e 100644 --- a/Multiton/Multiton.php +++ b/Multiton/Multiton.php @@ -46,6 +46,7 @@ class Multiton /** * gets the instance with the given name, e.g. Multiton::INSTANCE_1 + * uses lazy initialization * * @param string $instanceName * @return Multiton diff --git a/Prototype/Prototype.php b/Prototype/Prototype.php index 913be81..00036b2 100644 --- a/Prototype/Prototype.php +++ b/Prototype/Prototype.php @@ -6,7 +6,7 @@ namespace DesignPatterns; * Prototype pattern * * Purpose: - * to avoid the the cost of creating objects the standard way (new Foo()) and instead create a prototype and clone it + * to avoid the cost of creating objects the standard way (new Foo()) and instead create a prototype and clone it * * Examples: * - Large amounts of data (e.g. create 1,000,000 rows in a database at once via a ORM) diff --git a/Singleton/Singleton.php b/Singleton/Singleton.php index 16d4ca0..4da63d2 100644 --- a/Singleton/Singleton.php +++ b/Singleton/Singleton.php @@ -6,11 +6,11 @@ namespace DesignPatterns; * Singleton pattern * * Purpose: - * - to have only one instance of this object in the application, that handles all calls + * to have only one instance of this object in the application, that will handle all calls * * Examples: * - DB Connector - * - Logger (May also be a Multiton if there are many Logfiles for several purposes) + * - Logger (may also be a Multiton if there are many log files for several purposes) * - Lock file for the application (there is only one in the filesystem ...) * */ From 2653ed2aa929cf6a7541d6c6516bf430228047a4 Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Tue, 30 Aug 2011 12:34:45 +0200 Subject: [PATCH 2/3] added README --- README | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..4c12d8a --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +# design patterns in PHP + +This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a +small list of examples (most of them from Zend Framework or Doctrine2 as I'm most familiar with these). + +I think the problem with patterns is that often people know them but don't know when to apply which. + +*Please feel free to fork and add your own examples!* From 6d59edccf8622299305471683b2e2349c7a726ee Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Tue, 30 Aug 2011 14:49:09 +0200 Subject: [PATCH 3/3] readme is markdown and should then be named so --- README => README.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename README => README.markdown (57%) diff --git a/README b/README.markdown similarity index 57% rename from README rename to README.markdown index 4c12d8a..3faef03 100644 --- a/README +++ b/README.markdown @@ -1,8 +1,8 @@ -# design patterns in PHP +# design patterns in PHP # This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a -small list of examples (most of them from Zend Framework or Doctrine2 as I'm most familiar with these). +small list of examples (most of them from Zend Framework or Doctrine2 as I'm most familiar with this software). -I think the problem with patterns is that often people know them but don't know when to apply which. +I think the problem with patterns is that often people do know them but don't know when to apply which. *Please feel free to fork and add your own examples!*