refactoring pyramid of - java2days

45
Pyramid of Refactoring

Upload: others

Post on 15-Jan-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Refactoring Pyramid of - Java2Days

Pyramid of Refactoring

Page 2: Refactoring Pyramid of - Java2Days

About meWłodek KrakowskiTechnical and Organizational Trainer www.refactoring.pl

2

@wlodekkr

Page 3: Refactoring Pyramid of - Java2Days

RefactoringWorkshops

3© Copyright 2019 www.refactoring.pl

Page 4: Refactoring Pyramid of - Java2Days

What isRefactoring

1

Basics

Page 5: Refactoring Pyramid of - Java2Days

Refactoring Definition

5© Copyright 2019 www.refactoring.pl

(verb) to restructure software by applying a series of refactorings without changing its observable behaviour

Martin Fowler - Refactoring (2018)

Page 6: Refactoring Pyramid of - Java2Days

Refactoring Definition

6© Copyright 2019 www.refactoring.pl

(noun) A change made to the internal structure of the software to make it easier to understand and cheaper to modify without changing its observable behaviour

Martin Fowler - Refactoring (2018)

Page 7: Refactoring Pyramid of - Java2Days

Noticingthe Pyramid

2

My story

Page 8: Refactoring Pyramid of - Java2Days

100+ WorkshopsAfterthoughts

8© Copyright 2019 www.refactoring.pl

Page 9: Refactoring Pyramid of - Java2Days

Space between two main books...

9© Copyright 2019 www.refactoring.pl

Page 10: Refactoring Pyramid of - Java2Days

Refactoring by Martin Fowler

● Great catalogue of refactorings● One big sample at the beginning● Java/Javascript

This book is a great summary but it is like encyklopedia / dictionary to me

10© Copyright 2019 www.refactoring.pl

Page 11: Refactoring Pyramid of - Java2Days

Refactoring to Patterns by Joshua Kerievsky

● Expands the subject a lot● Contains lots of smaller samples● Requires reading a few times...

But each sample is already prepared to refactoring towards given design pattern This is rarely the case in legacy code

11© Copyright 2019 www.refactoring.pl

Page 12: Refactoring Pyramid of - Java2Days

Working with Legacy Code by Michael Feathers

● Different perspective● Also a kind of encyklopedia● Allows to find a starting point !!!

Does it contain a bigger vision among lots of useful & invaluable fixes?

12© Copyright 2019 www.refactoring.pl

Page 13: Refactoring Pyramid of - Java2Days

Basics...Arrangement...Order...

13

G

m

© Copyright 2019 www.refactoring.pl

Page 14: Refactoring Pyramid of - Java2Days

Pyramid of refactoring

Some theory at the beginning

3

Page 15: Refactoring Pyramid of - Java2Days

So simple?

15© Copyright 2019 www.refactoring.pl

Page 16: Refactoring Pyramid of - Java2Days

Flow● Nested Conditions● Nested Loops● Many Local Variables● Ambiguous Names● Single Exit Points

Can you read your code like a good book from the top and understand it quickly?

16© Copyright 2019 www.refactoring.pl

Page 17: Refactoring Pyramid of - Java2Days

Methods● Levels of Abstraction● Extract / Remove Parameter● Cohesion

Can you understand quickly what a method does at single level of abstraction?

17© Copyright 2019 www.refactoring.pl

Page 18: Refactoring Pyramid of - Java2Days

Classes● Extract Delegate● Extract Base Class● Extract Subclass● Extract field/constant

Do your classes have distinct areas of responsibility?

18© Copyright 2019 www.refactoring.pl

Page 19: Refactoring Pyramid of - Java2Days

Patterns● Abstractions● Interfaces

Dependencies defined as contract instead of implementation details knowledge

19© Copyright 2019 www.refactoring.pl

Page 20: Refactoring Pyramid of - Java2Days

Architectures● Packages● Modules● (Micro) Services

Can your architecture grow and scale easily by adding new or dividing existing components?

20© Copyright 2019 www.refactoring.pl

Page 21: Refactoring Pyramid of - Java2Days

Testing and Refactoring Twins

21© Copyright 2019 www.refactoring.pl

Page 22: Refactoring Pyramid of - Java2Days

Live Refactoring

You need to experience in order to understand

4

Page 23: Refactoring Pyramid of - Java2Days

Real Estates Catalogue

23© Copyright 2019 www.refactoring.pl

Page 24: Refactoring Pyramid of - Java2Days

Initial Project...

24© Copyright 2019 www.refactoring.pl

Page 25: Refactoring Pyramid of - Java2Days

It’s not me,It’s the team...

25© Copyright 2019 www.refactoring.pl

Page 26: Refactoring Pyramid of - Java2Days

LiveRefactoring

26© Copyright 2019 www.refactoring.pl

Page 27: Refactoring Pyramid of - Java2Days

27

We are climbing up the pyramid!

© Copyright 2019 www.refactoring.pl

Page 28: Refactoring Pyramid of - Java2Days

Lots of ways to refactor...

28© Copyright 2019 www.refactoring.pl

Specs classes achieved- Create Class (manually)

- Extract Delegate / Class

- Extract Parameter Object

Page 29: Refactoring Pyramid of - Java2Days

Live Refactoring

29© Copyright 2019 www.refactoring.pl

Page 30: Refactoring Pyramid of - Java2Days

S.O.L.I.D. in Pyramid

Basics again...

5

Page 31: Refactoring Pyramid of - Java2Days

S.O.L.I.D. Refactorings

31© Copyright 2019 www.refactoring.pl

● Single Responsibility Principle○ BelowAreaSpec, MaterialSpec, ...

● Interface Segregation Principle○ Spec

● Open Closed Principle○ ProductFinder.bySpec(Spec spec)

● Dependency Inversion Principle○ pl.refactoring.search.ProductFinder○ pl.refactoring.search.Spec○ pl.refactoring.search.spec.ColorSpec

Page 32: Refactoring Pyramid of - Java2Days

32© Copyright 2019 www.refactoring.pl

Page 33: Refactoring Pyramid of - Java2Days

Make it happen

Knowledge is the beginning...

6

Page 34: Refactoring Pyramid of - Java2Days

Share new experience

34© Copyright 2019 www.refactoring.pl

Emotions come first after each ● Workshop● Conference● Meeting● New Experience

… when you’ve learned something new

Page 35: Refactoring Pyramid of - Java2Days

Get new skills

35© Copyright 2019 www.refactoring.pl

Knowledge and skills are needed to keep the emotions● Review current skills● Make a learning plan● Introduce new skills step by step

Page 36: Refactoring Pyramid of - Java2Days

Emotions and Mind

36© Copyright 2019 www.refactoring.pl

Page 37: Refactoring Pyramid of - Java2Days

Trigger / Enablerefactoring

37© Copyright 2019 www.refactoring.pl

Code review opportunities● Readability● Testability● Extendibility● Design

Teamwork - each team member has equals rights to teach and learn

Page 38: Refactoring Pyramid of - Java2Days

VisualizeQuality Activities

38© Copyright 2019 www.refactoring.pl

To Do

Dev Code Review

Rework / Refactoring

Testing /Acceptance

DoneTo Do

Dev Code Review

Rework / Refactoring

Testing /Acceptance

Done

Page 39: Refactoring Pyramid of - Java2Days

Let’s summarize

What is the gap and its fulfillment?

7

Page 40: Refactoring Pyramid of - Java2Days

Pyramid is betweenthe books

40© Copyright 2019 www.refactoring.pl

Page 41: Refactoring Pyramid of - Java2Days

Each SamplePlacement

41

SAMPLE

SAMPLE

SAMPLE

SAMPLE

SAMPLE

© Copyright 2019 www.refactoring.pl

Page 42: Refactoring Pyramid of - Java2Days

Each SampleEmbracement

42

EACHBIG

SAMPLE

© Copyright 2019 www.refactoring.pl

Page 43: Refactoring Pyramid of - Java2Days

43© Copyright 2019 www.refactoring.pl

… but joining core books!

Not named explicitly...

Page 44: Refactoring Pyramid of - Java2Days

44

Q & A© Copyright 2019 www.refactoring.pl

Page 45: Refactoring Pyramid of - Java2Days

45

Thanks!www.refactoring.pl

- Blog- IT Trainings- Talks

Włodek Krakowski@wlodekkr