Dive_Into_Design_Patterns [Alexander_Shvets].pdf

(33091 KB) Pobierz
Dive Int o
e nt
DE SIGN
DES
PAT TERN S
TERNS
A Few Words on Copyright
Hi! My name is Alexander Shvets. I’m
the author of the book
Dive Into
Design Patterns
and the online course
Dive Into Refactoring.
This book is for your personal use only.
Please don’t share it with any third
parties except your family members. If you’d like to share the
book with a friend or colleague, buy and send them a
new copy.
All profit from the sale of my books and courses is spent on
the development of
Refactoring.Guru.
Each copy sold helps
the project immensely and brings the moment of a new book
release a little bit closer.
Alexander Shvets, Refactoring.Guru, 2019
support@refactoring.guru
Illustrations: Dmitry Zhart
Editing: Andrew Wetmore, Rhyan Solomon
I dedicate this book to my wife, Maria. If it
hadn’t been for her, I’d probably have finished
the book some 30 years later.
4
Table of Contents
Table of Contents
Table of Contents ....................................................................................... 4
How to Read This Book.............................................................................. 6
INTRODUCTION TO OOP ............................................................................. 7
Basics of OOP ................................................................................... 8
Pillars of OOP .................................................................................13
Relations Between Objects........................................................20
INTRODUCTION TO DESIGN PATTERNS.................................................23
What’s a Design Pattern? ............................................................24
Why Should I Learn Patterns?...................................................28
SOFTWARE DESIGN PRINCIPLES ...........................................................29
Features of Good Design ............................................................30
Design Principles.............................................................................34
§
Encapsulate What Varies ...............................................35
§
Program to an Interface, not an Implementation.39
§
Favor Composition Over Inheritance ........................44
SOLID Principles..............................................................................48
§
Single Responsibility Principle....................................49
§
Open/Closed Principle....................................................51
§
Liskov Substitution Principle .......................................54
§
Interface Segregation Principle...................................61
§
Dependency Inversion Principle .................................64
Zgłoś jeśli naruszono regulamin