Restructuring classes and behaviour

Post on 15-Apr-2017

162 views 0 download

transcript

Restructuring classes and behaviour

Wouter de Wild

PHP

JAVA

We should ban the extends

keyword from our language

- @n0xie

We should ban the extends

keyword from our language

- @n0xie But WHY?

We should ban the extends

keyword from our language

- @n0xie

Why do we use Object Oriented programming?

Why don’t use inheritance?

Animal

Dove Tiger

Animal

TigerBird (fly)

DoveParrot

GoldFish

Animal

TigerBird (fly)

DoveParrot

Fish

GoldFish Cod

Animal

TigerBird (fly)

DoveParrot

Fish (swim)

GoldFish Cod

Composition

Flexibility is keyword

Real code example

So how do we make this better?

So when do we use inheritance?

Actual Impl

Method 1

Method 2

Method 3

Interface

Composition

Method 1

Method 2

Method 3

Method 1

Method 2

Method 3

Interface

Inheritance

Method 2

What are the drawbacks of composition?

NUANCE is keyword

Summary

What is what?

Isolate behaviour

Inherit to specify for your purpose

Questions?