¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Software Design Pattern

vishal bhalerao Coding Inglés 1 página

Contenido del apunte (1)

Página 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

Información

Descripción
Coding Apunte sobre Software Design Pattern , creado por vishal bhalerao el 14/10/2017.
Creado por
vishal bhalerao
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?