|
Posted by Richard Levasseur on 08/23/06 07:41
I really like your site, since it provides clean, simple examples of
common patterns.
A few notes:
Pass the code through highlight_string for some basic syntax
highlighting, makes code a lot easier to read.
And:
I realized the one thing it is lacking though: an English description
of the code you're about to read. The opening blurbs are very terse
and don't explain the process and logic behind the pattern so much as
give a text book definition of what it is. The code itself is very
explanatory, but a providing a context can help immensely.
Ex: Singleton: In the singleton pattern a class can distribute one
instance of itself to other classes.
Might be better worded as: <what it means> <what it is suppose to do>
<purpose in software designing> <common method of implementation>
<special cases to note>
In the singleton pattern a class can control the instantiation of
itself to the user. This is akin to having a global instance of an
object, and is used when only a single instance of a class should
exist.
The common way of implementing this is storing a static, private
instance of the class within the class and using a static class
getInstance() method to fetch the stored instance.
This is useful for:
Database connections
Configuration classes
Controlling what instance a user gets
When class instances should be shared regardless of context
Feel free to copy/paste that and modify it as you wish.
[Back to original message]
|