restructuring classes and behaviour

76
Restructuring classes and behaviour Wouter de Wild

Upload: wouter-de-wild

Post on 15-Apr-2017

162 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Restructuring classes and behaviour

Restructuring classes and behaviour

Wouter de Wild

Page 2: Restructuring classes and behaviour

PHP

JAVA

Page 3: Restructuring classes and behaviour

We should ban the extends

keyword from our language

- @n0xie

Page 4: Restructuring classes and behaviour

We should ban the extends

keyword from our language

- @n0xie But WHY?

Page 5: Restructuring classes and behaviour

We should ban the extends

keyword from our language

- @n0xie

Why do we use Object Oriented programming?

Page 6: Restructuring classes and behaviour

Why don’t use inheritance?

Page 7: Restructuring classes and behaviour
Page 8: Restructuring classes and behaviour

Animal

Dove Tiger

Page 9: Restructuring classes and behaviour

Animal

TigerBird (fly)

DoveParrot

GoldFish

Page 10: Restructuring classes and behaviour

Animal

TigerBird (fly)

DoveParrot

Fish

GoldFish Cod

Page 11: Restructuring classes and behaviour

Animal

TigerBird (fly)

DoveParrot

Fish (swim)

GoldFish Cod

Page 12: Restructuring classes and behaviour

Composition

Page 13: Restructuring classes and behaviour
Page 14: Restructuring classes and behaviour
Page 15: Restructuring classes and behaviour
Page 16: Restructuring classes and behaviour
Page 17: Restructuring classes and behaviour
Page 18: Restructuring classes and behaviour
Page 19: Restructuring classes and behaviour
Page 20: Restructuring classes and behaviour
Page 21: Restructuring classes and behaviour
Page 22: Restructuring classes and behaviour
Page 23: Restructuring classes and behaviour
Page 24: Restructuring classes and behaviour
Page 25: Restructuring classes and behaviour
Page 26: Restructuring classes and behaviour
Page 27: Restructuring classes and behaviour
Page 28: Restructuring classes and behaviour
Page 29: Restructuring classes and behaviour
Page 30: Restructuring classes and behaviour
Page 31: Restructuring classes and behaviour
Page 32: Restructuring classes and behaviour
Page 33: Restructuring classes and behaviour
Page 34: Restructuring classes and behaviour
Page 35: Restructuring classes and behaviour
Page 36: Restructuring classes and behaviour
Page 37: Restructuring classes and behaviour
Page 38: Restructuring classes and behaviour
Page 39: Restructuring classes and behaviour
Page 40: Restructuring classes and behaviour
Page 41: Restructuring classes and behaviour
Page 42: Restructuring classes and behaviour
Page 43: Restructuring classes and behaviour
Page 44: Restructuring classes and behaviour
Page 45: Restructuring classes and behaviour

Flexibility is keyword

Page 46: Restructuring classes and behaviour
Page 47: Restructuring classes and behaviour
Page 48: Restructuring classes and behaviour
Page 49: Restructuring classes and behaviour

Real code example

Page 50: Restructuring classes and behaviour
Page 51: Restructuring classes and behaviour
Page 52: Restructuring classes and behaviour
Page 53: Restructuring classes and behaviour
Page 54: Restructuring classes and behaviour

So how do we make this better?

Page 55: Restructuring classes and behaviour
Page 56: Restructuring classes and behaviour
Page 57: Restructuring classes and behaviour
Page 58: Restructuring classes and behaviour

So when do we use inheritance?

Page 59: Restructuring classes and behaviour
Page 60: Restructuring classes and behaviour
Page 61: Restructuring classes and behaviour

Actual Impl

Page 62: Restructuring classes and behaviour

Method 1

Method 2

Method 3

Interface

Composition

Method 1

Method 2

Method 3

Page 63: Restructuring classes and behaviour

Method 1

Method 2

Method 3

Interface

Inheritance

Method 2

Page 64: Restructuring classes and behaviour
Page 65: Restructuring classes and behaviour

What are the drawbacks of composition?

Page 66: Restructuring classes and behaviour
Page 67: Restructuring classes and behaviour

NUANCE is keyword

Page 68: Restructuring classes and behaviour
Page 69: Restructuring classes and behaviour
Page 70: Restructuring classes and behaviour
Page 71: Restructuring classes and behaviour

Summary

Page 72: Restructuring classes and behaviour
Page 73: Restructuring classes and behaviour
Page 74: Restructuring classes and behaviour
Page 75: Restructuring classes and behaviour

What is what?

Isolate behaviour

Inherit to specify for your purpose

Page 76: Restructuring classes and behaviour

Questions?