- In this solution, we didn't have…to modify index.php at all.…Instead, all of our work is in the shapes.php file.…In this solution, we went with a K statement.…Since there are only two options,…we could have used an if else,…but odds are we'll get more shapes,…so we might as well think of this now.…Further, we have a number of exit points to this function.…In some languages this is problematic,…but in PHP there are no issues with it.…In fact, by returning immediately,…we're less likely to hit other issues…such as a forgotten break statement, or similar.…Our circle and square classes are pretty simple, too.…Their constructors are essentially identical,…we're just capturing the incoming value…and storing it for later.…
Then our get area method calculates the area…according to what you'd expect.…There's one potential issue here.…Since the radius and side are protected values,…we don't have a way outside the constructor to modify them.…These objects are immutable, or unchangeable.…If we need to modify a circle or square, we'll actually have…
Author
Released
1/28/2015- Accessing data with the active record and table data gateway patterns
- Creating objects with the factory, singleton, and mock objects patterns
- Extending code with decorator and adapter patterns
- Structuring applications with MVC and Action-Domain-Responder patterns
Each chapter features a design pattern in a real-world coding scenario, and closes with a practice challenge to test your new skills.
Skill Level Intermediate
Duration
Views
Related Courses
-
PHP: Creating Secure Websites
with Kevin Skoglund4h 15m Intermediate -
PHP: Accessing Databases with PDO and MySQLi
with David Powers3h 47m Intermediate
-
Introduction
-
Welcome51s
-
-
1. The Active Record Pattern
-
2. The Adapter Pattern
-
3. The Decorator Pattern
-
4. The Factory Pattern
-
5. Mock Objects
-
Introducing mock objects2m 18s
-
-
6. The Model-View-Controller Pattern
-
7. The Action-Domain-Response Pattern
-
8. The Publish/Subscriber Pattern
-
9. The Singleton Pattern
-
10. The Strategy Pattern
-
11. The Table Data Gateway Pattern
-
Conclusion
-
Next steps2m 8s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Solution: Apply the factory pattern