GoConqr has a new look! Let us know what you think.

Notes

Software Design Pattern

vishal bhalerao Coding English 1 page

Content of the notes (1)

Page 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

Information

Description
Coding Note on Software Design Pattern , created by vishal bhalerao on 14/10/2017.
Created by
vishal bhalerao
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?