background preloader

Five common PHP design patterns

Five common PHP design patterns
Editor's note: See the follow-up article "Five more PHP design patterns" to learn about five additional design patterns that you might find useful. Design patterns were introduced to the software community in Design Patterns, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (colloquially known as the "gang of four"). The core concept behind design patterns, presented in the introduction, was simple. Over their years of developing software, Gamma et al found certain patterns of solid design emerging, just as architects designing houses and buildings can develop templates for where a bathroom should be located or how a kitchen should be configured. Design patterns not only present useful ways for developing robust software faster but also provide a way of encapsulating large ideas in friendly terms. It's difficult to demonstrate the value of patterns using small examples. The factory pattern The problem is tight coupling. Listing 1 shows an example of a factory class. <? <? <?

PrinciplesOfOod The Principles of OOD What is object oriented design? What is it all about? What are it's benefits? Of all the revolutions that have occurred in our industry, two have been so successful that they have permeated our mentality to the extent that we take them for granted. Programs written in these languages may look structured and object oriented, but looks can be decieving. In March of 1995, in comp.object, I wrote an article that was the first glimmer of a set of principles for OOD that I have written about many times since. These principles expose the dependency management aspects of OOD as opposed to the conceptualization and modeling aspects. Dependency Management is an issue that most of us have faced. The first five principles are principles of class design. The next six principles are about packages. The first three package principles are about package cohesion, they tell us what to put inside packages: Sincerely, Henrik Robert, yes thank you, I'm aware of those. Hi Bob! Regards

PHP Patterns: Observer Pattern | Floriansweb Das Observer/Subject Pattern ist vom theoretischen recht klar, doch wie setzte ich so ein Pattern in der Praxis ein. Zuerst will ich das klassische Pattern an einem Beispiel aus meinem Bereich vorstellen und danach dieses Pattern erweitern. Zuerst benötigen wir zwei Interfaces: Observer, Observable: interface Observer { public function update ( Observable $observable ) ; } interface Observable { public function attach ( Observer $observer ) ; public function detach ( Observer $observer ) ; public function notify ( ) ; } Dem Observable können mit attach/detach Observers hinzugefügt und entfernt werden. Hier folgendes Szenario: Ich habe ein Product Object welches die Eigenschaften Titel, Beschreibung, Preis etc hat. Hier also unsere Product Klasse welche die Schnittstelle und die entsprechenden Getter/Setter für implementiert public class Product implements Observable { protected $title ; private $_dirty ; public function setTitle ( $title ) { if ( $this -> getTitle ( ) ! Ergebnis: “ ” Bsp:

How To Enable Dragging in SVG | CodeDread Blog SVG allows you to do quite a bit in terms of graphics in the browser that was not possible without a special plugin like Flash. This post describes how I enabled dragging of entities around the screen. Introduction If you are unfamiliar with SVG I would recommend checking out my two Kickstart tutorials here: One and Two. Furthermore, you can see many useful examples at SVGBasics. My goal was to create an SVG document that allowed the user to drag entities around the screen as they do with existing windowing environments today. SVG Events In SVG 1.1, you can hook up event handlers to SVG entities by techniques that should be familiar to most HTML/JS coders nowadays: When the rectangle is clicked on, the JavaScript function buttonClick() will be called which lets you do whatever you want. Dragging Now that you understand how to hook up event handlers, the basics of a dragging operation are: SVG Mouse Coordinates In my investigations, I started with this post by Jonathan Watt on the Yahoo!

Flash’s Future Fades as Windows Close on Adobe | Gadget Lab Microsoft gave out Samsung Windows 8 tablets at its 2011 BUILD Conference. Image: VentureBeat The future of Flash looks dimmer and dimmer as another major player in the mobile space shuns support of the platform. Microsoft’s brand new Windows 8 Metro user interface will not support Adobe Flash or other plug-ins, instead embracing the HTML5 set of web standards, according to Microsoft’s Internet Explorer team leader Dean Hachamovitch. For users who access legacy ActiveX controls, they’ll have to jump out of the Metro UI and switch to the classic-styled desktop browser. Hachamovitch explains that running IE without Flash or other plug-ins “improves battery life as well as security, reliability, and privacy for consumers.” “Providing compatibility with legacy plug-in technologies would detract from, rather than improve, the consumer experience of browsing in the Metro style UI,” Hachamovitch wrote in a blog post on Thursday. And Android isn’t the only OS running Flash poorly. Note 1.

Browser Statistics

Related: