Chapter 14
Chapter 14
Design
Chapter 14
3 Design Patterns
in Web Context 4 Data and
Domain
Patterns
5 Presentation
Patterns
7
Section 1 of 5
REAL WORLD WEB SOFTWARE DESIGN
Real-World Software
Design
Software design can mean many things.
In general, it is used to refer to the planning activity
that happens between gathering requirements and
actually writing code.
This chapter has an overview of some of the typical
approaches used in the software design of web
applications
Challenges
In designing real-world applications
PRINCIPLE OF LAYERING
Challenges
In designing real-world applications
Remind you of
actually
shopping?
Section 3 of 5
DESIGN PATTERNS IN THE WEB CONTEXT
Software Design Patterns
Same old problem
Will not solve all your problems, but they will help you
design better code if used thoughtfully.
It is a clear and concise way to describe
algorithms/code
The most common design patterns are those that were
identified and named in the classic 1995 book Design
Patterns: Elements of Reusable Object-Oriented
Software
Adapter Pattern
http://sourcemaking.com/design_patterns/adapter
Adapter Pattern
UML Diagram For the database
adapter
Adapter Pattern
Interface for adaptor
Adapter Pattern
Concrete Classes (partial implementation)
Adapter Pattern
Concrete Classes (partial implementation)
Any client classes (or pages) that needs to make use of the
database will do so via the concrete adapter:
$connect = array(DBCONNECTION, DBUSER, DBPASS);
$adapter = new DatabaseAdapterPDO($connect);
$sql = 'SELECT * FROM ArtWorks WHERE ArtWorkId=?';
Creating the properties along with their getters and setters for all
the domain objects in a model can be very tedious.
PHP does provide its own type of shortcut via the __get() and
__set() magic methods
The __get() method is called when a client of a class tries to
access a property that is not accessible.
Magic occurs with the idea of Variable variables that PHP allows
“ $this-> “ is used to refer to an instance of an object inside on of
the object's methods.
Getters and Setters
Magic
For instance
• if $name contains the string 'yearOfBirth'
• then $this->$name == $this->yearOfBirth.
__Set()
Example usage
Example
Example Domain Model
Example
Example Domain Class
Domain Object and
Gateway
Retrieving and Saving
Active Record Pattern
Interface with the database
PRESENTATION PATTERNS
Model View Controller
MVC
Advantages:
Separate presentation
and application logic
3 Design Patterns
in Web Context 4 Data and
Domain
Patterns
5 Presentation
Patterns