Quantcast
Channel: The Code Collective » design patterns
Browsing all 7 articles
Browse latest View live

Polyton Design Pattern

/* * The Polyton Design Pattern * By Adam J Nowak ~ http://hyperspatial.com * * Creates unique numbered class instances and allows you to run a different set of functions for the first instance of the...

View Article



Strategy Pattern

<?php /* ~~~~~~~~~~~~~ Car Repair Classes ~~~~~~~~~~~~~ */ abstract class CarRepair{ protected $_duration,$_cost_calculator; public function __construct($duration, CostCalculator $cost_calculator){...

View Article

Factory Pattern

<?php interface GirlInterface{ function get_name(); function get_hair_color(); } class Girl implements GirlInterface{ protected $_name,$_hair_color; public function __construct($name,$hair_color){...

View Article

Abstract Factory Pattern

<?php /* ~~~~~~~~~~~~~ Factory Classes ~~~~~~~~~~~~~ */ abstract class RobotFactory{ abstract function build_male_robot(); abstract function build_female_robot(); } class WorkRobotFactory extends...

View Article

Prototype Pattern

<?php class Cone{} class PlainCone extends Cone{} class WaffleCone extends Cone{} class IceCream{} class VanillaIceCream extends IceCream{ private $brand = 'Ben & Jerry\'s';//For something to...

View Article


Composite Pattern

<?php abstract class Horse{ abstract function get_horsepower(); } class Pony extends Horse{ public function get_horsepower(){ return 0.7; } } class RidingHorse extends Horse{ public function...

View Article

Decorator Pattern

<?php abstract class Goggle{ abstract function get_impairement_of_judgement(); } class BeerGoggle extends Goggle{ private $_impairement_of_judgement = 0; public function...

View Article
Browsing all 7 articles
Browse latest View live


Latest Images