Architecture and Design Patterns
Architecture and Design Patterns
patterns
Jonathan Einav
Lecture Objectives
Open a window to the architecture and
design patterns world, explain why are
they needed and where did they came
from, and give some examples and real
world tastes of chosen DP and
architectures
not a programming language oriented
lecture, we will mainly discuss the
paradigms and uses with examples in
various programming languages.
Programming paradigms Evolution
Block Programming
Procedural programming
Object Oriented
Component Oriented
SOA (?)
What are design patterns?
The Beginning - “Gang of four” (Gama et al
1995)
Example:
Button expose a clicked event that encapsulate click
state, thus publish himself as an observable. Clients that
are interested in this event register to it, thus becomes
observers.
Observer and observable are bonded in a contract and
can be completely loosely coupled from one another.
Singleton design pattern
Creational pattern
ensure that a class has only one instance, and to provide a global
point of access to it
Example:
Class SomeClass
{
static SomeClass singleTonInstance = null;
static void produce(object stateInfo)
{
eventProducerDone.Set();
while (true)
{
//wait for the consumer
eventConsumerDone.WaitOne();
currentNum++;
eventProducerDone.Set();
}
}
Consumer/Producer - example
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(new
WaitCallback(produce));
for (int i = 0; i < 20; i++)
{
eventProducerDone.WaitOne();
System.Diagnostics.Debug.WriteLine(currentNum);
eventConsumerDone.Set();
}
}
Model View Controller
The Model-View-Controller (MVC) pattern
separates the modeling of the domain, the
presentation, and the actions based on
user input into three separate classes
The controller changes the model
The View Listens to Model
Changed events and
update itself
Recursive MVC
N tier Architecture
The n tier architecture is based on the
concept of separating a system to
different layers (usually 3) Each layer
interacts with only the layer directly
below, and has specific function that it
is responsible for.
Classic for IT systems
N tier Architecture
3 Tier architecture:
Presentation Layer
Presentation Layer is the layer responsible for displaying user interface.
Business Tier
Business Tier is the layer responsible for accessing the data tier to
retrieve, modify and delete data to and from the data tier and send the
results to the presentation tier. This layer is also responsible for
processing the data retrieved and sent to the presentation layer.
BLL and DAL
Often this layer is divided into two sub layers: the Business Logic Layer
(BLL), and the Data Access Layers (DAL). Business Logic Layers are
above Data Access Layers, meaning BLL uses DAL classes and
objects. DAL is responsible for accessing data and forwarding it to BLL.
Data Tier
Data tier is the database or the source of the data itself.