Professional Documents
Culture Documents
Department of Information Engineering 395 Design Patterns
Department of Information Engineering 395 Design Patterns
Search... Search
Download presentation
Des gnButtons:
patterns
• What s a pattern?
2
– Pattern descr bes a problem wh ch occurs
over and over aga n n our env ronment, and
Cancel Download
then descr bes the core of the solut on to that
problem, n such a way that you can use th s
solut on a m ll on t mes over , . . .
1 / 209
Similar presentations
Department of Information Engineering 395
Design patterns What is a pattern? –Pattern
describes a problem which occurs over and
over again in our environment,
Published by Michael Haskell Modi ed over 5 years ago
To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie
policy. I agree. /
Embed
Download presentation
Download presentation
24 Department
To make this website work, we of
logInformation Engineering
user data and share 418 Factory
it with processors. To use Method
this website, you must agree to our Privacy Policy, including cookie
policy. I agree. /
De ne an interface (the virtual functions) for creating an object, but let
subclasses decide which class to instantiate. Factory Method lets a class
defer instantiation to subclasses. Also known as virtual constructor
Download presentation
25 Department of Information Engineering 419 Framework, toolkit
and application What is the di erence between framework, toolkit and
application? –Framework has the highest degree of reuse, and is the
We think you have liked this presentation. If you wish to
most exible –Application is the least exible
download it, please recommend it to your friends in any social
system. Share buttons are a little bit lower. Thank you!
26 Department of Information Engineering 420 What is a
Buttons:
framework? A framework is an abstract type of software that captures
the design decisions that are common to its application domains –e.g.
what is the similarity between a circuit design editor, and musical score
editor? –Both manipulate graphical objects An abstract software
(framework) that can support both applications? 2
34 DepartmentButtons:
of Information Engineering 428 Pros and cons of
class inheritance Pros –Simpler than object delegation, codes are easier
to follow Cons –Static binding, xed at compilation time, cannot be
changed at run-time –Need to create new subclass Ways to reduce the
number of subclasses? 2
41
To make this website work, we of
Department logInformation
user data and share it with processors.
Engineering To use this
435 Abstract website,
Factory
policy. I agree.
Inyou must agree to our Privacy Policy, including cookie
/
many applications, we don’t change just one type of object, but, rather,
a family of objects This can be done by using a factory object To select
a di erent game at run-time –Just change the (concrete) factory object f
Abstract Factory provides an interface for creating families of related or
Download presentation
dependent objects without specifying their concrete classes
To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie
62 Department of Information Engineeringpolicy. 456 The consideration
I agree. /
To make the object easily accessible –Use a global/static object
Drawback –No guarantee that there is only one instance of the class,
e.g. static Singleton object_1 = new Singleton(); static Singleton object
_2 = new Singleton(); Problem - two objects of the same class Solution -
Download presentation
use a private constructor !
82 DepartmentWe of Information
think you haveEngineering
liked this 476 Recursive If
presentation. object
you wish to
structure aPicture aLineaCircle
download it, aPicture
please aLineaCircle
recommend it to your friends in any social
system. Share buttons are a little bit lower. Thank you!
83 Department of Information Engineering 477 Composite code
Buttons:
example class Graphic { public virtual void Draw(); //... } class Picture :
Graphic { private ArrayList graphics; //container public void Draw() {
foreach (object o in ArrayList) { Graphic g = (Graphic) o; g.Draw(); //if g
is-a line, draw line } //if g is-a picture, recursion }
2
102 Cancel
Department of Information Engineering 496 Proxy application Download
virtual proxy (as in our example) –creates expensive objects on demand
–e.g. virtual memory in an OO Unix remote proxy –provides a local
representative for an object in a di erent address space (e.g CORBA,
RMI,.NET) protection proxy –control access to the original object
(authentication) smart reference –replacement of a bare pointer that
performs additional actions, e.g. web page ltering
163 DepartmentWeofthink
Information
you have Engineering 557 Solution Ifbyyou wish to
liked this presentation.
subclassing But subclassing
download makes it di recommend
it, please cult for an object to change
it to your friends in any social
the algorithm at runsystem.
time The algorithm
Share buttons is statically binded
are a little to the
bit lower. Thank you!
concrete object Base Class void Algo(); Derived Class A void Algo();
Derived Class B voidButtons:
Algo();
Strategy Same class diagram, same pattern of code ! –Di ered by their
intent and dynamics State’s intent –Allow an object to alter its behavior
when its internal state changes Strategy’s intent –De ne a family of
algorithm, encapsulate each one, and make them interchangeable
2
197 Department of Information Engineering 591 Patterns in MVC
Controller –Strategy pattern –Take care of the UI, di erent UI uses
di erent controller Model-View –Observer pattern –model is the
subject, views are the observers, View –Composite pattern –a Cancel Download
CompositeView may contain more Views
Buttons:
Cancel Download
To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie
policy. I agree. /
Download presentation
Buttons:
Cancel Download
Search... Search
To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie
policy. I agree. /
Download presentation
Buttons:
Cancel Download
To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie
policy. I agree. /