Digital Library

PHP OOP Way (Sergey Zhuk)(Z-Library)

Sergey Zhuk

PHP OOP Way (Sergey Zhuk)(Z-Library)

Author Sergey Zhuk

php
Language English

Chapter 1 covers the fundamentals of the object-oriented programming: encapsulation, inheritance, and polymorphism. We will discuss the purpose of abstraction and inheritance, and why you should avoid using inheritance for code reuse. This chapter also covers such language specific features as traits and closures and their role in the object-oriented code. And at the end of the chapter, I will introduce such a powerful tool as Dependency Injection, different types of it and some code smells of its wrong usage. Chapter 2 is fully devoted to SOLID principles. We will discuss each of them: the main idea behind the principle, how to apply it to your code and some problems that you can face following these principles blindly. Chapter 3 is an introduction to an object-oriented design. It covers the well knows design principles such as: Tell, don't ask The Law of Demeter YAGNI Kiss Dry This chapter also covers some basic anti-patterns that you can meet in the code with poor design. Chapter 4 opens the topic of the design patterns and composition. We will discuss the difference between inheritance and composition and when each of them is more appropriate to use. This chapter covers such design patterns as State, Strategy, Adapter and their comparison with the inheritance approach. Chapter 5 describes the problem “I don't have the interface that I want.”. We will cover situations when we need to make two incompatible interfaces work together and how to reduce the complexity of the subsystem and hide it behind the friendly interface. Chapter 6 is about GRASP principles and Responsibility Driven Design. It is often a challenge to choose the right object for a particular job and to decide how the objects should interact with each other. Correct responsibility assignments are the key to a good object oriented design. Who Is This Book For This is not a beginner's guide to OOP PHP. We are not going to cover the syntax of classes or the difference between public, protected a

Format EPUB
Size 348.7 KB
197
Views
0
Downloads
0.00
Total Donations

AI Guide

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

Full assistant
AI guide
【One-Line Pitch】 A practical, intermediate-to-advanced guide to object-oriented design in PHP, teaching you how to move beyond syntax and build maintainable, well-designed systems through encapsulation, SOLID principles, design patterns, and responsibility-driven thinking. Ideal for developers who know PHP basics but want to deepen their architectural judgment. 【Book Arc】 - **Opening (~0%–8%)**: Sets expectations — this is not a beginner's tutorial. The author assumes you know PHP syntax and OOP basics, and instead focuses on the "why" behind design decisions, from encapsulation to composition. - **Early (~8%–26%)**: Builds the foundation with a deep dive into encapsulation, using a `User` class example to show how bundling data with methods creates real objects rather than data structures. Introduces abstraction as a way to define new types, not just reuse code. - **Early–Middle (~26%–45%)**: Continues the `User` example, adding validation and business logic (like `isYoung()`) to demonstrate how a public interface protects invariants. Discusses setters, constructors, and why hiding properties matters. - **Middle (~45%–55%)**: Shifts to abstraction as type definition — classes as new data types that combine data and behavior. Warns against using inheritance for code reuse, calling abstraction "the worst way" to achieve it. - **Late (~55%–end)**: Covers SOLID principles, design principles (Tell Don't Ask, Law of Demeter, YAGNI, KISS, DRY), anti-patterns, composition vs. inheritance, patterns like State/Strategy/Adapter, and GRASP for responsibility assignment. The excerpts do not detail these chapters' code examples, but the arc is clear: from fundamentals to advanced design thinking. 【Key Takeaways】 - **Encapsulation is about building a safe public interface** (Early): Hide properties, expose methods that enforce business rules — like `isYoung()` instead of raw `getAge()` — so client code can't misuse your objects. This makes changes localized and code more robust. - **Classes are new data types, not just code containers** (Middle): A class like `User` defines a type with both data and behavior, unlike an array. This abstraction helps developers understand and use your code correctly. - **Avoid inheritance for code reuse** (Middle): The author explicitly calls abstraction "the worst way" to reuse code. Prefer composition and interfaces to share behavior without coupling hierarchies. - **Validation belongs in the object, not the client** (Early–Middle): Use constructors and setters with logic (e.g., `abs()` for age) to prevent invalid states like negative ages. This keeps business rules in one place. - **Design principles guide, but don't dictate** (Late): SOLID, Tell Don't Ask, and YAGNI are tools, not rules — following them blindly can make code worse. Understand the intent behind each principle. - **Composition beats inheritance for flexibility** (Late): Patterns like State, Strategy, and Adapter show how to swap behavior dynamically, which inheritance makes rigid. Choose composition when you need runtime variability. - **Responsibility assignment is key to good design** (Late): GRASP principles help decide which object should handle a task, leading to clearer interactions and more maintainable systems. 【Reading Tips】 - **Deep-read the early chapters (0%–45%)**: The `User` class example is the core teaching device — follow it closely to internalize encapsulation and interface design. This is where the book's value is most concrete. - **Skim the SOLID and pattern chapters (55%+)**: If you already know these concepts, focus on the author's critiques and "blind following" warnings — that's the unique insight. If new, read slowly and apply to your own code. - **Treat code snippets as illustrations, not production templates**: The author explicitly says examples are not production-ready. Use them to understand ideas, then adapt to your context. - **Pause and refactor your own code**: After each chapter, try applying one principle (e.g., hide a property, add a validation method) to a real class in your project. This book rewards hands-on practice. - **Watch for the "why" behind each rule**: The author constantly asks "why" — why hide data, why avoid inheritance. If you find yourself nodding without understanding, re-read the surrounding explanation. 【Coverage Limits】 This guide covers the book's opening chapters (encapsulation, abstraction, and the `User` example) in detail, but the later chapters on SOLID, design patterns, and GRASP are only summarized from the table of contents — the excerpts do not include their full content.

Passage locations

Excerpt 1
Is This Book For This is not a beginner's guide to OOP PHP. We are not going to cover the syntax of classes or the difference between public, protected a PH...
View in text
Excerpt 2
lass. Consider this object as a real client in front of you. You can see his or her face, clothes, eyes color. You can speak to a client, ask some questions ...
View in text
Excerpt 3
age</code><code class="p">;</code>   <code class="c1">// ...</code>   <code class="p">}</code>   <code class="k">public</code> <code class="k">function</code...
View in text
Excerpt 4
e don’t allow a client code to set a negative age to a user. Now, we can update our constructor to use setAge method and the last issue with age will be fixe...
View in text

Support Author

0.00
Total Amount (¥)
0
Donation Count
Please enter an amount Minimum ¥1

You will be redirected to Alipay to complete payment, then return here.

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List