Elements of Object-oriented Design

50 %
50 %
Information about Elements of Object-oriented Design
Education

Published on February 24, 2014

Author: sicarii_13

Source: slideshare.net

Description

Object Oriented programming, coupled with Design Patterns—including those provided by the Standard PHP Library—is the key to re-usable and highly modular code

ELEMENTS OF OBJECTORIENTED DESIGN CPTR304: INTERNET AUTHORING HENRY OSBORNE

DESIGN PATTERNS GENERALLY RECOGNIZED AS AN EXCELLENT SET OF TRIEDAND-TRUE SOLUTIONS TO COMMON PROBLEMS THAT DEVELOPERS FACE EVERY DAY

DESIGN PATTERN THEORY DESIGN PATTERNS ARE NOT REALLY ABOUT CODE AT ALL— THEY SIMPLY PROVIDE GUIDELINES THAT THE DEVELOPER CAN TRANSLATE INTO CODE FOR PRETTY MUCH EVERY POSSIBLE LANGUAGE.

THE SINGLETON PATTERN • PROBABLY THE SIMPLEST DESIGN PATTERN. • ITS GOAL IS TO PROVIDE ACCESS TO A SINGLE RESOURCE THAT IS NEVER DUPLICATED, BUT THAT IS MADE AVAILABLE TO ANY PORTION OF AN APPLICATION THAT REQUESTS IT WITHOUT THE NEED TO KEEP TRACK OF ITS EXISTENCE.

class DB { private static $_singleton; private $_connection; private function __construct() { $this->_connection = mysql_connect(); } public static function getInstance() { if (is_null (self::$_singleton)) { self::$_singleton = new DB(); } return self::$_singleton; } } $db = DB::getInstance();

THE FACTORY PATTERN USED IN SCENARIOS WHERE YOU HAVE A GENERIC CLASS (THE FACTORY ) THAT PROVIDES THE FACILITIES FOR CREATING INSTANCES OF ONE OR MORE SEPARATE “SPECIALIZED” CLASSES THAT HANDLE THE SAME TASK IN DIFFERENT WAYS.

class Configuration { const STORE_INI = 1; const STORE_DB = 2; const STORE_XML = 3; public static function getStore($type = self::STORE_XML) { switch ($type) { case self::STORE_INI: return new Configuration_Ini(); case self::STORE_DB: return new Configuration_DB(); case self::STORE_XML: return new Configuration_XML(); default: throw new Exception("Unknown Datastore Specified."); } } } class Configuration_Ini { // ... } class Configuration_DB { // ... } class Configuration_XML { // ... } $config = Configuration::getStore(Configuration::STORE_XML);

THE REGISTRY PATTERN BY TAKING THE SINGLETON PATTERN A LITTLE FURTHER THE REGISTRY PATTERN CAN BE IMPLEMENTED. THIS ALLOWS THE USE OF ANY OBJECT AS A SINGLETON WITHOUT IT BEING WRITTEN SPECIFICALLY THAT WAY.

class Registry { private static $_register; public static function add(&$item, $name = null) { if (is_object($item) && is_null($name)) { $name = get_class($item); } elseif (is_null($name)) { $msg = "You must provide a name for non-objects"; throw new Exception($msg); } $name = strtolower($name); self::$_register[$name] = $item; } public static function &get($name) { $name = strtolower($name);

if (array_key_exists($name, self::$_register)) { return self::$_register[$name]; } else { $msg = "’$name’ is not registered."; throw new Exception($msg); } } public static function exists($name) { $name = strtolower($name); if (array_key_exists($name, self::$_register)) { return true; } else { return false; } } }

$db = new DB(); Registry::add($db); // Later on if (Registry::exists(’DB’)) { $db = Registry::get(’DB’); } else { die(’We lost our Database connection somewhere. Bear with us.’); }

THE MODEL-VIEW-CONTROLLER (MVC) PATTERN • PROVIDES A METHODOLOGY FOR SEPARATING THE BUSINESS LOGIC (MODEL) FROM THE DISPLAY LOGIC (VIEW) AND THE DECISIONAL CONTROLS (CONTROLLER)

M-V-C

THE ACTIVERECORD PATTERN THIS IS USED TO ENCAPSULATE ACCESS TO A DATA SOURCE SO THAT THE ACT OF ACCESSING ITS COMPONENTS—BOTH FOR READING AND FOR WRITING—IS, IN FACT, HIDDEN WITHIN THE CLASS THAT IMPLEMENTS THE PATTERN, ALLOWING ITS CALLERS TO WORRY ABOUT USING THE DATA, AS OPPOSED TO DEALING WITH THE DATABASE.

SUMMARY • OBJECT ORIENTED PROGRAMMING, COUPLED WITH DESIGN IS THE KEY TO REUSABLE AND HIGHLY MODULAR CODE. • THE MORE FORETHOUGHT YOU GIVE YOUR DESIGN, THE MORE LIKELY YOU ARE TO BE ABLE TO RE-USE AT LEAST SOME OF IT, LATER, SAVING TIME AND EFFORT IN THE FUTURE—NOT TO MENTION THAT PROPER DESIGN TECHNIQUES ALSO MAKE CODE EASIER TO MAINTAIN AND EXTEND. • BRINGING THIS EXPERIENCE TO THE TABLE MAKES YOU TRULY VERSATILE; DESIGN PATTERNS ARE, LARGELY LANGUAGE- AND PROBLEM-INDEPENDENT.

ELEMENTS OF OBJECTORIENTED DESIGN

Add a comment

Related presentations

Related pages

Design Patterns:Elements of Reusable Object-Oriented ...

Gamma Erich - Design Patterns:Elements of Reusable Object-Oriented Software: Elements of Reusable Object jetzt kaufen. ISBN: 9780201485370, Fremdsprachige ...
Read more

Design Patterns. Elements of Reusable Object-Oriented ...

Amazon.de. Design Patterns is a modern classic in the literature of object-oriented development, offering timeless and elegant solutions to common problems ...
Read more

Design Patterns : Elements of Reusable Object-Oriented ...

Design Patterns: Elements of Reusable Object-Oriented Software 7 Preface to Book This book isn't an introduction to object-oriented technology or design.
Read more

Design Patterns - Wikipedia, the free encyclopedia

Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing recurring solutions to common problems in software ...
Read more

Object Oriented Design

Object-Oriented Design ... analysis structures will transition into model elements of the target system. OO Design 4 Relationship of OO A&D. OO Design 5
Read more

Object-oriented analysis and design - Wikipedia, the free ...

Object-oriented analysis and design (OOAD) is a popular technical approach for analyzing, designing an application, system, or business by applying the ...
Read more

Elements of Object-Oriented Program Design

CHAPTER 1. FROM SCHEME TO JAVA 6 Consider the following example: assume that a Java program can access an Entry object e and needs to get the value of the ...
Read more

Design Patterns: Elements of Reusable Object-Oriented ...

Lesen Sie Design Patterns: Elements of Reusable Object-Oriented Software Elements of Reusable Object-Oriented Software von Erich Gamma mit Kobo. Capturing ...
Read more

Entwurfsmuster (Buch) – Wikipedia

Entwurfsmuster. Elemente wiederverwendbarer objektorientierter Software (Originaltitel Design Patterns. Elements of Reusable Object-Oriented Software) ist ...
Read more

Design Patterns | Object Oriented Design

Design Pattern Books: Forum ... resources in shared mode - Other design patterns implemented ... to access the elements of an aggregate object sequentially ...
Read more