Book Image

Learning Design Patterns with Unity

By : Harrison Ferrone
Book Image

Learning Design Patterns with Unity

By: Harrison Ferrone

Overview of this book

Struggling to write maintainable and clean code for your Unity games? Look no further! Learning Design Patterns with Unity empowers you to harness the fullest potential of popular design patterns while building exciting Unity projects. Through hands-on game development, you'll master creational patterns like Prototype to efficiently spawn enemies and delve into behavioral patterns like Observer to create reactive game mechanics. As you progress, you'll also identify the negative impacts of bad architectural decisions and understand how to overcome them with simple but effective practices. By the end of this Unity 2023 book, the way you develop Unity games will change. You'll emerge not just as a more skilled Unity developer, but as a well-rounded software engineer equipped with industry-leading design patterns.
Table of Contents (23 chapters)
21
Other Books You May Enjoy
22
Index

Summary

That’s going to close out our Decorator pattern discussion, but let’s review the key points before you jump to your own projects. First, the Decorator pattern is best used when you want to change the skin of an object instance and not the inner workings of its class. If you want to dynamically change the guts of a class, refer to Chapter 12, Swapping Algorithms with the Strategy Pattern. This solution is a wonderful option in lieu of inheritance and large class hierarchies.

The Decorator pattern is made up of the main Component interface, concrete Component classes, the Decorator abstract class, and concrete Decorator classes. Both the concrete Components and concrete Decorators in your projects need to implement the Component interface so the client can treat them the same. Your decorators function as transparent wrappers for the Components you want to decorate, adding or modifying the Component in some way while also calling the Components’ base...