پی اچ پی

Open-Closed Workshop

Open-Closed Workshop

In this workshop, we'll focus exclusively on the open-closed principle (the O in SOLID). Using real-life code, line by line, we'll refactor a confusing class into something far more manageable and extendable. Once finished, we'll have gained the luxury of introducing new functionality, not by modifying existing code, but by instead writing a new class class.



سطح حرفه ای 5 جلسه آموزشی 00:27:00 ساعت
01
قسمت 1

What We Are Refactoring

In order to provide a practical, real-life example of the open-closed principle, we'll use a heavily-modified version of existing code from the Laracasts codebase, itself. This should open up all sorts of refactoring possibilities. Now before we get started, let's first take a few minutes to discuss what we're working with, and where we want to go.

02
قسمت 2

Low-Hanging Refactors

Let's begin our refactoring by applying the squint test. If we squint our eyes and scan the Query, what immediately jumps out at us? Indentation? Common method names? Multiple return types? Let's see!

03
قسمت 3

Remove Conditionals and Embrace the Pipeline

Let's keep going. In this episode, I'll show you how to remove a conditional by reassigning the "check" to the underlying class.

04
قسمت 4

Extract What Changes into a Service Provider

Let's take the only remaining thing that changes in our Query class, and extract it to a service provider. With this tweak, you'll never have to modify the Query class again. Instead, create a new featured collection, add a new item to your service provider's $collections array, and you're done.

05
قسمت 5

Discussing Responsibility

As we reach the end of this series, let's take a few moments to discuss responsibility and awareness. I find that it's useful to frequently ask myself, "Should this class be aware of that particular thing?"

دوره در حال اجرا

این دوره هنوز به پایان نرسیده است و در آینده درس های دیگری به آن افزوده خواهد شد.