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

Upgrading Façades

There’s no rule in the Façade pattern that says you can only have a single type of façade, which means you may find yourself in situations where an abstract base class comes in handy. While this isn’t something new or revolutionary for you object-oriented folks, you could have a Façade class like the one in the following code that all other façades must implement:

public abstract class AbstractFacade : MonoBehaviour
{
    public abstract IEnumerator Save(double score);
}

Then you could derive concrete subclasses any way you like – for example, different auto-save façades dealing with cloud and disk storage, as seen in the following snippet:

public class CloudStorageFacade : AbstractFacade
{
    public override IEnumerator Save(double score)
    {
        yield break;
    }
}
public class LocalStorageFacade : AbstractFacade
{
    public override IEnumerator Save(double score)
    {
        yield break...