Design Patterns Summer Course 2009-2010 - Session#3

Preview:

DESCRIPTION

 

Citation preview

Lecture # 3Ahmed Safwat

Muhamad HeshamAbdelrahman Al-Ogail

Let’s break the ice….

Agenda

You can solve it yourself! Meet Singleton pattern. Call for a new requirement. First try for implementation. Bad smell code. Who’s our hero?

Agenda (con’t)

Meet today’s pattern.Break!! Second try for implementation. Common uses. What’s next?

What’s a design pattern?

A design pattern is: Set of class(es). Interact together. In UML (class diagram).

Informa

l

Let’s solve it ourselves

How do we ensure that

a class has only one instance and that

the instance is easily accessible?

Unique

Global

Access

Singleton

The Singleton assures that there is one and only one instance of a class, and provides a global point of access to it

Make sure that there can be one and only one instance of a class

Formal

Singleton

Our Current Status

What have we did till now?

Call for New Requirement

Each level can be in one of two styles: Pharonic Aztec

First level is Aztec. Second and third level is

Pharonic.

First Try Implementation

1. We need find where we decide which image we load.

2. Categorize images to 2 sets, Pharonic an Aztec.

Our Code Smells Bad

Each time we add a new

theme we add piles of if-else statements.

Our class do more than

its job (SCSR).

My Restaurant Drinks

My Restaurant Drinks

My Restaurant Drinks

Water Bottle

Coke softOrange

softLemon

soft

Who’s our hero?

So, what we can call it?

Let’s Google it!

Break

Meet Abstract Factory

Meet Abstract Factory

Coke soft

Lemon soft

Second Try for Implementation

Just Code It

Common Uses

What’s Next?

Consequences of Factory Pattern.

Factory Method Pattern.

Implement Factory Pattern using Prototype Pattern.

Thank you ...

Questions??ahmedaliyossef@acm.orgmhesham.fcis@gmail.com

zikas_zak@hotmail.com