O GoConqr está de visual novo! Conte para nós o que você achou.

Notas

Software Design Pattern

vishal bhalerao Coding Inglês 1 página

Conteúdo das notas (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

Informações

Descrição
Coding Notas sobre Software Design Pattern , criado por vishal bhalerao em 14-10-2017.
Criado por
vishal bhalerao
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?