Post on 24-May-2015
Design Patterns| What is a Pattern?
A Design Pattern is essentially a description of a commonly occurring object-oriented design problem and how to solve it
A Design Pattern is essentially a description of a commonly occurring object-oriented design problem and how to solve it
Design Patterns| An object-oriented design problem
Imagine a system that uses a number of temperature sensors to monitor the condition of a hardware device of some sort.
The first model of the device uses Indus, Inc. TS7000 sensors.
Indus supplies a simple Java class to interface with the sensors:
class TS7000 {native double getTemp();...
}Here is some monitoring code that simply calculates the mean temperature reported by the sensors.
double sum = 0.0;for (int i = 0; i < sensors.length; i++)sum += sensors[i].getTemp();double meanTemp = sum / sensors.length;
Note that sensors is declared as an array of TS7000 objects.
(TS7000 sensors[ ] = new TS7000[...])
Imagine a system that uses a number of temperature sensors to monitor the condition of a hardware device of some sort.
The first model of the device uses Indus, Inc. TS7000 sensors.
Indus supplies a simple Java class to interface with the sensors:
class TS7000 {native double getTemp();...
}Here is some monitoring code that simply calculates the mean temperature reported by the sensors.
double sum = 0.0;for (int i = 0; i < sensors.length; i++)sum += sensors[i].getTemp();double meanTemp = sum / sensors.length;
Note that sensors is declared as an array of TS7000 objects.
(TS7000 sensors[ ] = new TS7000[...])
Design Patterns| An object-oriented design problem
The second model of the device uses more temperature sensors and the design uses a mix of TS7000s and sensors from a new vendor, eSoft.
The eSoftsensors are SuperTemps and a hardware interfacing class is supplied:
class SuperTempReader {//// NOTE: temperature is Celsius tenths of a degree//native double current_reading();...}
Here is a terrible way to accommodate both types of sensors:for (int i = 0; i < sensors.length; i++)
{
if (sensors[i] typeof TS7000)sum += ((TS7000)sensors[i]).getTemp();else// Must be a SuperTemp!sum +=((SuperTempReader)sensors[i]).current_reading() * 10;
}In this case sensors is an array of Objects. The type is tested withtypeof and an appropriate cast and method call is performed.
The second model of the device uses more temperature sensors and the design uses a mix of TS7000s and sensors from a new vendor, eSoft.
The eSoftsensors are SuperTemps and a hardware interfacing class is supplied:
class SuperTempReader {//// NOTE: temperature is Celsius tenths of a degree//native double current_reading();...}
Here is a terrible way to accommodate both types of sensors:for (int i = 0; i < sensors.length; i++)
{
if (sensors[i] typeof TS7000)sum += ((TS7000)sensors[i]).getTemp();else// Must be a SuperTemp!sum +=((SuperTempReader)sensors[i]).current_reading() * 10;
}In this case sensors is an array of Objects. The type is tested withtypeof and an appropriate cast and method call is performed.
Design Patterns| A pattern to the rescue!
Any problems here?
What's terrible about this code?
Which pattern is suitable for it?
Types of Patterns- Classification- GOF
Any problems here?
What's terrible about this code?
Which pattern is suitable for it?
Types of Patterns- Classification- GOF
Design Patterns| Patterns for Web application development
Web development Issues- automated testing- UI are hard to test- Changing nature of web- Frequent changes in UI Design
How to solve this issue?- Separate UI and Business Objects
MVC- Model View Controller
MVP- Model View Presenter
Web development Issues- automated testing- UI are hard to test- Changing nature of web- Frequent changes in UI Design
How to solve this issue?- Separate UI and Business Objects
MVC- Model View Controller
MVP- Model View Presenter
Design Patterns| Model – View - Controller
Controller
Model View
Deman
d
Data
Response
Request
Design Patterns| Model – View - Presenter
Presenter
Model
View Implementation
Dem
and
Dat
a
ResponseRequ
est
View Interface
Design Patterns| ASP.NET MVC 3
A part of the ASP.NET Web application framework
It enables clean separation of concerns, testability, and TDD by default
It is highly extensible and pluggable
A part of the ASP.NET Web application framework
It enables clean separation of concerns, testability, and TDD by default
It is highly extensible and pluggable
Design Patterns| Web Client Software Factory
Quickly incorporate many of the proven practices and patterns of building Web client applications
Provides proven solutions to common challenges found while building and operating large transaction processing enterprise Web sites
Support for the Model-View-Presenter pattern
Contains a collection of reusable components and libraries, Visual Studio 2005 and Visual Studio 2008 solution templates, wizards and extensions, How-to topics, automated tests, extensive architecture documentation, patterns, and a reference implementation
Quickly incorporate many of the proven practices and patterns of building Web client applications
Provides proven solutions to common challenges found while building and operating large transaction processing enterprise Web sites
Support for the Model-View-Presenter pattern
Contains a collection of reusable components and libraries, Visual Studio 2005 and Visual Studio 2008 solution templates, wizards and extensions, How-to topics, automated tests, extensive architecture documentation, patterns, and a reference implementation
Design Patterns| Demo