GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Notizen

Software Design Pattern

vishal bhalerao Coding Englisch 1 Seite

Inhalt der Notizen (1)

Seite 1

Strategy pattern

basic Principals :-

1. Avoid duplication of codes and

2. change in superclass should not break code in sub class neither add any functionality that subclasses cannot perform logically.

problem statement ?

if we want to add feature in super class (animal) but some of subclasses need it some of dont( fly func need in bird but not in dog).

but directly adding to super class will make dogs fly.

we can override func in every subclass to make it do something or or just dont do anything so dogs will not fly

this will make lot of duplicate code.

Other solutions :-

creating interface in super class d forcing all subclasses to implement it . but using interface as y to force classes to implement func is bad idea

here comes the strategy :-

using the concept - reference of interface can refer object of class which implements that interface .

create interface of given func.

create classes which implement that interface . each class represents possible way to implement that func.

create super class which has field of interface reference

setter receive object of class from step 2,

getter executes function returns out put.

this is called decoupling as we are encapsulating variable functionality

Informationen

Beschreibung
Coding Notiz am Software Design Pattern , erstellt von vishal bhalerao am 14/10/2017.
Erstellt von
vishal bhalerao
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck