- PeterMoulding.com
- Author
- Trainer
- Speaker
- Business Coach
- How to write a How To book
- PHP Courses
- Speaking
- Web Architect
- Australia
- Books
- Authors
- Akkana Peck
- Alex Berenson
- Andrew Nugent
- Ben Sanders
- Brock Clarke
- Chris Simms
- David Mercer
- Dianna Mullet
- Don Winslow
- Dori Smith
- Harlan Coben
- Jack McDevitt
- James Wines
- Jerry Yudelson
- John Grisham
- Kevin Mullet
- L. E. Modesitt Jr.
- Laurell K. Hamilton
- Marshall Karp
- Martina Cole
- Michael Marshall Smith
- Michel Roux Jr
- Nadia Sawalha
- Philip Pullman
- Raymond Khoury
- Richard North Patterson
- Robert Masello
- Sally Roth
- Sarah Langan
- Stella Rimington
- Stephen Booth
- Stephen King
- Stephen Leather
- T.C. Boyle
- Tom Negrino
- Tony Hillerman
- Urban Waite
- Val McDermid
- Valerio Massimo Manfredi
- Beginning GIMP
- Beginning Visual C++
- Culturalism
- Fiction
- A Drink Before The War
- A Talent for War
- Bag of Bones
- Blood and Ice
- Burn
- Dark Lady
- Dead Line
- Eclipse
- Empress of Eternity
- Exley
- Flipping Out
- Just One Look
- Nightfall
- Pet Sematary
- Savage Moon
- Skinwalkers
- Starvation Lake
- The Fallen
- The Gardens of the Dead
- The Jump
- The Last Templar
- The Mermaids Singing
- The Midnight Mayor
- The Secret Soldier
- The Summons
- The Terror of Living
- The Testament
- The Tower
- Under the Dome
- Virus
- AJAX and PHP
- Aging with Grace
- Food books
- Green Architecture
- Life Is So Good
- SQL: The Complete Reference
- The Backyard Bird Lover's Ultimate How-to Guide
- The Garden Gurus
- Authors
- Sustainability
- -18 hours left to decide the future of Australia
- Campbells vegetable stock or Massel vegetable stock?
- Carbon Sequestration
- Carbon tax for Australia is a fraud
- Copenhagen will fail
- Cost of living in Australia
- Dick Smith jumps on the population bandwagon
- Dry Run: Preventing the Next Urban Water Crisis
- Energy Saving Lights
- Garlic
- How many people can live in Australia?
- Its obsolete, throw it out!
- Julia Gillard offers 9.9 billion dollars bribe to Rob Oakeshott
- Laundry detergent
- Petrol or Diesel?
- Reflective foil batts kill
- RoHS
- Sea level to rise 3mm due to climate change
- Solar power
- Spring again in Sydney
- Sustainable fuels
- The CRUD Tax is back
- The people who make building regulations do not own houses
- Water efficiency
- Which insulation is safer, foil or wool?
- Will Australia reduce greenhouse gas emissions?
- Technology
- Android or Blackberry or iPhone or a flip phone?
- Apple versus Google 2011
- Cameras
- Cars
- Colour
- Burgundy
- Colour Blindness
- Colour Names
- Dulux colours
- Pantone colours
- Safe Colours
- Seculine ProDisk Mini colour balance card
- What Causes Colour Blindness?
- Hardware
- Batteries for the Digital Age
- Cables
- Cases
- Computer reliability
- Computrace
- Disks
- Astone ISO Gear 481E
- Best SSD for your notebook computer
- Disk block size
- Hitachi disk HDS722020ALA330
- LaCie USB 2.0 250 GB mobile hard drive design by F.A. Porsche
- SMART disk
- Samsung 2 TB HD204UI quiet low power disk for mass storage
- Seagate and Samsung merge disk business
- Select the right disk for your RAID array
- USB disk speed
- Western Digital WD20EARX 2 GB SATA 3 disk
- How long should computer hardware last?
- Keyboards
- Mainframe
- Memory cards
- Monitors
- Netbooks, notebooks, tablets, and xPads
- Network Attached Storage
- OLED Displays
- PC's are a thing of the past
- Printers
- Quiet
- Samsung Galaxy S
- Speed
- Television
- Tools
- USB
- Worst computer movies
- Xserve is dead. What next?
- Your backup will not work
- Z68 motherboards
- iPad or Acer Aspire One?
- IQ
- LG Intello Washing Machine
- Lack of a challenge
- Networks
- 802.11n wireless networking
- D-Link DIR-655 wireless router
- D-Link DWA-160 Xtreme N dual band USB adapter
- D-Link DWA-556 Xtreme N PCI Express desktop adapter
- MIMO
- NBN spends another $12 billion of our tax money on nothing
- National Broadband Network
- Netgear wireless modem router DGND3300 with 300 Mbps 802.11n
- Refrigerator kills wireless broadband
- Small Wireless Network
- TP-LINK TL-SG10005D 5 port gigabit switch
- TP-Link TL-WR1043N wireless N gigabit router
- Telstra Pre-paid Mobile Wi-Fi
- Where are the router plus proxy server combinations?
- Open Source documentation
- Software
- 7-zip
- Accounting
- Asterisk
- Audacity
- Backup software
- Bloat only in Windows
- CAD
- CDex
- Disk imaging software for copying and backup
- Exact Audio Copy
- Filezilla
- Firefox
- Java
- LibreOffice or OpenOffice?
- Linux
- 1 in 5 servers will ship with Linux
- Android phones outsell iPhone
- Another Move to Linux
- CentOS 5.5 installation on SSD and RAID 5
- Debian
- Debian 5.0.5 AMD64 installation
- Debian 5.06 installation
- Fedora
- Fedora or Ubuntu?
- Gnome or KDE?
- K9copy
- Linux 2.6.38
- Linux Gnome login settings lost
- Linux Mint
- Linux RAID, a rant
- Linux Speed
- Linux Time
- Linux reliability as demonstrated by Ubuntu 10.10
- Linux reliability as demonstrated by Ubuntu 11.4
- Linux still a struggle in 2011
- Linux workstation disk RAID 1
- Linux, NT, Windows, and SETI
- Linux, three years of progress
- London Stock Exchange switches to Linux
- Mandrake Linux 9.2
- The partition is misaligned by 48128 bytes - warning from Linux RAID
- Ubuntu
- How to fix the scroll bars in Ubuntu 11.4 Gnome
- Kubuntu 10.10 alternate installation on desktop with RAID 1
- POWbuntu
- Ubuntu 10.10 after 6 months use
- Ubuntu 10.10 alternate installation
- Ubuntu 10.10 desktop RAID 1
- Ubuntu 10.10 desktop RAID 5
- Ubuntu 10.10 desktop install on a netbook
- Ubuntu 10.10 desktop installation
- Ubuntu 10.10 netbook install on a netbook
- Ubuntu 10.10 server AMD64
- Ubuntu 10.10 upgrade to version 11.4 beta 2
- Ubuntu 10.4
- Ubuntu 11.10
- Ubuntu 11.10 first upgrade
- Ubuntu 11.4 after one month use
- Ubuntu 12.04 beta1 desktop amd64
- Ubuntu One
- Ubuntu by Microsoft?
- Ubuntu desktop upgrade 10.4 to 10.10 failed because I did not check the media
- Ubuntu strikes again
- Upgrade Ubuntu to Linux Mint 12 LDXE for extra speed
- Yes, use Linux but not that distribution!
- Nero
- OpenOffice
- OpenOffice is now Apache Office
- Project management
- Scribus
- Software for Windows and Linux
- Text editors
- Time
- Todo applications
- Tomboy notes
- Top text editors
- Version control
- VideoLAN VLC media player
- Visio
- Webmin
- Webmin installation on CentOS for Web development
- Webmin installation on Ubuntu
- What is the most popular open source software today?
- Windows
- Another Windows person goes Linux
- BAD_POOL_CALLER
- Cygwin
- Microsoft Malicious Software Removal Tool cannot find a common virus
- One of the developers of Windows XP is criminally insane
- There are unused icons on your desktop
- W32time
- Which Windows version?
- Windows 7 Home Premium
- Windows XP Stop 0x0000007B during installation
- Windows XP is a disaster
- Windows processes
- XML
- Zip, bzip, gzip, or 7zip?
- configFree
- Technology Succession Planning
- VoIP
- Web Sites
- Drupal
- Do Drupal themes have to use the GPL?
- Drupal 7
- A better search facility for Drupal
- Drupal - performance or flexibility
- Drupal 7 Fields are hard to fix
- Drupal 7 new features
- Drupal 7 ships on January 5
- Drupal 7.14
- Drupal 7.4 hits PeterMoulding.com
- Drupal function sequence
- The evolution of a module
- Undefined index: headers in DefaultMailSystem->mail() (line 54 of /modules/system/system.mail.inc).
- Undefined index: to in DefaultMailSystem->mail() (line 83 of /modules/system/system.mail.inc).
- implode(): Invalid arguments passed in DefaultMailSystem->format() (line 23 of /modules/system/system.mail.inc).
- Drupal 8
- Drupal Code Load Cut
- Drupal How To
- Drupal Modules
- Backup and Migrate
- Browscap
- CKEditor with Drupal WYSIWYG
- Captcha
- Cel
- Colorbox
- Content Construction Kit
- Content type
- Devel module for Drupal
- Drupal Rules as an automation language
- Drupal Spam add-on module
- Form alter to node
- IMCE
- IMCE Wysiwyg bridge
- ImageAPI
- Jdog
- Lightbox2
- Module variable
- Node Gallery Access
- Node_Gallery
- Path
- Path redirect
- Pathauto
- Pet
- Search
- Service links
- Session Variable
- Statistics
- Taxonomy
- Token
- Token ex
- Transliteration
- Trigger
- Watch
- Other modules
- Drupal Training
- Drupal access controls need a major rewrite
- Drupal coding tricks
- Drupal performance
- Drupal themes for the future
- Drupal.org colours
- Import existing data into Drupal
- Multiple Web sites made easy using Drupal multisite and the right start
- drupal_lookup_path()
- Adobe PDF
- Apache
- Apache Mahout
- Audi.com
- Bleet
- CSS Strikes Again
- CSS or xCSS
- Can you believe Facebook or email?
- Content Management Systems
- Databases
- Facebook scam
- Font
- Fonts
- HTML
- Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre
- Language Codes
- Marketing
- Memcache
- Nginx
- Open source development hits another roadblock
- Oscars
- PHP
- SPDY
- Search software
- Techoni.com.au
- Theme themes
- Things to hate on Web sites
- U.S. Patent No. 6,985,875
- Virtual Private Server
- Visible Improvement
- Web 4.0
- Web browser usage
- Web browsers
- Web site development
- Bluefish
- Crying over spilt code
- Eclipse and PHP
- Getting a Git client, a story of ancient technology and pain
- HTTrack
- MVC
- Netbeans
- PHP or ..., CakePHP/Symfony/ZF versus ...
- Programming
- Superfish
- Web browser emulators for testing your Web site
- Web development frameworks
- Web site books
- Web site development on your own computer
- Webmin or phpMyAdmin or cPanel for creating databases?
- aiki framework
- jQuery
- Views development - Learn Fields first
- Views development - Learn Actions and Rules
- jQuery .each()
- jQuery .has()
- jQuery .is()
- jQuery and Firefox Firebug
- jQuery children
- jQuery for people not using Drupal - Installation and getting started
- jQuery hover
- jQuery hover de-duplication example
- jQuery or CSS?
- jQuery performance
- jQuery tests
- Web site hosting
- Westpac Web site still broken after two years and ten months
- Wordpress wins another CMS survey
- Drupal
PHP design patterns
Submitted by Peter on Fri, 2011-04-15 10:27
technology:
Some programmers and teachers like to promote design patterns to improve code reliability. Frameworks replace design patterns in the commercial world. Content management systems replace frameworks in most new projects. Do design patterns have a place in modern programming? Do Java based design patterns help or damage PHP based Web development? Here is the future based on real experience.
Job prospects
Job descriptions do not mention design patterns, they mention frameworks, content management systems, and degrees. Programmers looking for programming roles will look at the challenging jobs involving PHP and databases, jobs which often request experience with Cake, Symfony, Zend, or one of the other frameworks. People with an artistic flair will most likely end up working with a content management system producing themes.
Some jobs require a degree and the person hiring the graduate might prefer a graduate from the same university. Graduates of Sydney University look for graduates from Sydney University. I sat in a meeting where a large number of middle level managers bragged about graduating from Sydney University. We were going around the table introducing ourselves. There were three of us in the group who had not graduated from Sydney University and one was looking like the victim of school yard bullies. How could I interrupt the preening and bullying? I had visited Cambridge, if only for coffee and a walk along the river. Fortunately the first non Sydney University graduate was a lady who said Harvard. The bragging stopped. (The lady graduated somewhere else.)
Your degree type and source are more important than any design patterns you learnt while attending classes.
Patterns or frameworks
Some development frameworks classify their code classes based on patterns. PHP is so flexible that there are high speed functions to perform some of the things described in patterns without creating special classes. It is sometimes useful to classify classes by patterns but not useful to change classes to fit artificial definitions of patterns.
The really important things within a framework are consistency to make the framework easy to learn and best use of the programming language, which may mean code and patterns different from Java where most of the patterns are originally described. PHP has natural data and list processing built it. There is rarely a need to slow down an application with junk code inserted purely to emulate an approach used in Java. The approach used in Java is used in Java purely because Java is missing so many basic data related features.
Frameworks provide greater productivity increases than patterns. In fact patterns do not provide any productivity increase, patterns are really only a documentation tool. If you define a class as a singleton, future programmers know it should have only one collection of values based on a unique identifier and will not try to add other items. I remember a case where a contact class was modified to have multiple addresses. There was already an address class but the new programmer ignored the address class and added address information to the contact class. There had to be at least two addresses, one for home and one for work. What the programmer should have done, and might have done if the programmer followed design patterns and the contact class was documented as a singleton, was to put the person related information into a person class then use the contact class to group together a person and a list of addresses. The person and address classes would be singletons and the contact would become something else.
The patterns
- Data transfer object or DTO or Value object
- Factory
- Singleton
Some other patterns include Active record, Adapter, Data mapper, Decorator, Iterator, Mock object, Model-View-Controller, Observer, Proxy, Registry, Specification, Strategy, and Table data gateway.
Data transfer object
The Data transfer object, or dto, used to be called a value object and was only needed for the Java programming language because the Java programming language lacks data storage. PHP has genuine native data storage, a far more efficient and flexible approach.
If you want to invent a dto for PHP, you could create a dto for dates because dates can be used in a lot of different formats and a date object could provide that compatibility. The instant you add date format conversion to your date dto, the dto is no longer a dto, it becomes a Singleton or some other design pattern.
When you store data in PHP lists, arrays, you can use lots of high speed searches and other efficient techniques on the data. If you replace each data item with a dto, you have to create slow inefficient code to find and work with the data. That horrible artificial code is one reason why some activities in some PHP frameworks can be as slow as Java.
The Web has ignored dtos for data transfer. There are lots of standards in place for data transfer and none of the commonly used standards uses dtos. Java dto creators add extensions to their dtos to let the dtos be serialised for transfer through the standards that do not waste time on dtos. The instant you add data serialisation to a dto, the dto is no longer a dto.
Factory
A Factory pattern class or object creates objects. That seems useless in PHP where object creation is so easy. The real use is in code where you combine already loaded data. You might be creating an address object. Someone selects a country and your code creates a country object. The person selects a city from the list for that country and your code creates a city object. Next the person enters address information and your code creates an address object. The address object contains a postcode formatted for the country and selected based on the city. If you create a factory class to create the address object, the factory can use the country and city objects to create an address object with some data customised for they country and city.
You would only use a factory class if there is something unique you can add to the created object based on known data at the time of creation. You could only use a factory where you create a lot of objects with the same input. Factories fail when people try to build in lots of business logic to create different objects with unrelated data.
As an example, I created a framework that included a country class and a factory for creating objects that used the country information. In effect all the factory did was create the object from the class then use a method to set a link to the country object. I have worked on projects where the factory is then expanded to do many different things and maintenance is almost impossible. Instead, for the framework, I built factories that used other factories. Most data related objects were created by a database related factory that added in common database processing links. The country factory called the database factory to create a database related object then the country factory added in the country information and returned the object. The contact factory called the country factory to get contact objects customised by country. There were other factories using factories. Each factory did one unique thing, could be maintained independently from the other factories, and could be tested without running the whole application.
Singleton
The Singleton is a Data transfer object with additional code. The code is for validation or to create compatibility.
The name Singleton indicates there is one value or item stored in the object. The item might be a compound value or a collection of data with a single relationship but not a list.
An example compound value is a telephone number with an area code. The area code is kept separate from the number because in some circumstances you do not dial the area code. The combination of area code and number represents a single telephone number and is a singleton.
An example of a collection of data with a single relationship that is a singleton is a row from a database. The row might be a contact entry containing an address and the telephone number at that address. There is just one contact and it is a singleton.
An example of a collection of data with a single relationship that is not a singleton is a list of the telephone numbers within an area code. Their one relationship is the area code. The list is not a singleton.
Conclusion
Use patterns to help classify your existing code, not to artificially restrict it to emulating the slow difficult bits of Java.








