0% found this document useful (0 votes)
4 views

LLD__Design_Patterns__Decorator_and_Flyweight_Design_Pattern

The document discusses the Decorator and Flyweight design patterns, illustrating their applications in software development. It provides examples related to an ice cream ordering application and a multiplayer online game, highlighting how these patterns can optimize resource usage and enhance functionality. Key concepts include the separation of intrinsic and extrinsic properties in the Flyweight pattern and the dynamic addition of behaviors in the Decorator pattern.

Uploaded by

Anupal Neog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

LLD__Design_Patterns__Decorator_and_Flyweight_Design_Pattern

The document discusses the Decorator and Flyweight design patterns, illustrating their applications in software development. It provides examples related to an ice cream ordering application and a multiplayer online game, highlighting how these patterns can optimize resource usage and enhance functionality. Key concepts include the separation of intrinsic and extrinsic properties in the Flyweight pattern and the dynamic addition of behaviors in the Decorator pattern.

Uploaded by

Anupal Neog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Agent

Decorator Design Pattern


mm ft mhm mm Mhm
HTML SpringAppin

Design Pattern
y
Flyweight
Pubg
SWE at radical Knality walls Amul
Ione cream vending machine

Application that take orders for come ice creams

Description
cone t black current scoop t strawberry
orange
scoop t mango scoop t cherry
Y

Build an ice cream

Cost
of the ice cream
list of ingredients
Description of ice
cream

17
getlost11 getDescription
satin

yigttyiiiimnfqt.mg'T
ITI
giggtimate

histstopping
getlostex

U
Dessel
I get

I
V

1
MIngredient
getlost17

t
tf

lone mÉ come
on
Syrup scoop
Them

Icecream

histangsidients ing

addingridient CK

i
getcost 121
I
DescDS
get
Decorator Design Pattern

Right from beginning I had an

xp icecream cone
Whenever we are adding something new

cost dese get added too


V

Define an interface abstract class that represents the


Steph
are trying to construct
thing at we

R Ice Cream77
getlost 1
getDescription

have
There are 2 Kinds of ingredients that
we
Steph
tour is a base ingredient

W U
Toppings are
add on

h Addons
Base 7
me
at H ETHIER
IMI
orange
For each of these define a clan and each class implements
Step3
the ice cream interface

LeIuecreant
f get lost 17

iI

Chou

Only a base entity

getlost1 getyou cost of that entity


getperp11
name of cone

base have ADD one


After you

t hd
costblack
currant

Black
L
gottes ell t strawberryscoop t await
5005 500

Hft

kzaxj.gg

woot
Ice Creams

Wydonttone
i
drowsyup
Tovecream in
getloster ie
gethostlk Chaoyang
return10 I return15
I this.ie i i
I getDerek ie getlost 15
getDerek getlost1
return Chocosyrup
return or i getdue1 ie getbeset

I
new dhow Scoop
Iman ie
Vanilla scoop
new
Come
new Chocolate
new Chocosyrup
A
Icecream
new OrangeCon

I
ingetcostl finalcast
beset 9 finddesup
ie get
Decorator Design Pattern
we have an entity to which we want to change behaviours
If may
consider using decorator design pattern
add to it's behaviour at runtime

HII
HTML element

Eggman
Fyi

Elements new margin I


KATMI new Border
C
display
new Button1
y
y
whine
C
SpringBoot run

I
bur cache Decorate
envity
Enablesprings
web Application
is both base and add on it will have 2 constructors
If a class

empty constructor

constructor which takes param of interface

Orangelone 1
Ice cream ie
OrangeCowell
E
I
Icreenean it
orangeCone

this is is

f I
getlost

return to
I Hiiiii

www.t
Flyweight Design Pattern

Ingineer building the


UI of a multiplayer online Battle Royale game
PUBG

Chandan Alok
i
ga Fa 1

ygy
2guns player
300bullets player at a time

5 56 m m 7 62m 7
9mn
double 813
thus SAME
cower SAME
enumlint YB
weight SAME
double 813
maxDamage SAME
int YB
ni t t z I X
direction y
double 2413 X
speed
double 2B SAME
manRange
int YB
curloor X
100000 bullets
targetCoor X
I
as 1Pub game
MB
by71 IKB image SAME
2 I IKB

RAM und by bullet


Total
I I A 103 B lot
A

A 108 B
I I
O H GB
I tooMB

Even though you have too ooo bullets not all the
Cajon bullets are completely
distinct from each other

todiff types of bullets


pushes
often we have
classes that have 2 types of properties

Intrinsic
Extrinsic valueof which remains
whichmight Sanne arose all objects
Values of
changewith time

whose objects demonstrate intrinsic


class
flyweight If you have a

properties AND if you


see that there
as well as extrinsic
usage because of this you consider
is extra memory
using flyweight design pattern

Divide that class into 2


classes

it withonly intrinsic properties


with only extrinsic properties

Centrinsic Bullet intrinsic


flying Bullet
direction 2913 radius
813 color
speed
MB weight
uncoor man Damage
72713
targettoo man Ranyn
Bullet bullet
of
storesreference sweet
Igad image
actual
gall
E
III
Duby
has to types of bullets
to Bullet objects
Got KB toKB

There are still 100000 flying Bullets


100 ooo FB objets
for A 88 B
8.9 A 106 B 8 8 MB

8.8 MBT IKB I


Total Space 9Mt
9M
11ooMB
optimisation

You might also like