游戏编程模式-子类沙盒模式

2020-07-07  本文已影响0人  _day_day_up_

Subclass Sandbox Pattern 子类沙盒模式

Intent 意义

Define behavior in a subclass using a set of operations provided by its base class.


使用基类提供的操作集合来定义子类中的行为。

The Pattern 模式描述

A base class defines an abstract sandbox method and several provided operations. Marking them protected makes it clear that they are for use by derived classes. Each derived sandboxed subclass implements the sandbox method using the provided operations.


一个基类定义了一个抽象的沙盒方法和一些预定义的操作集合。通过将它们设置为受保护的状态以确保它们仅供子类使用。每个派生出的沙盒子类根据父类提供的操作来实现沙盒函数。

When to Use It 使用情形

The Subclass Sandbox pattern is a very simple, common pattern lurking in lots of codebases, even outside of games. If you have a non-virtual protected method laying around, you’re probably already using something like this. Subclass Sandbox is a good fit when:

沙盒模式是运用在多数代码库里、甚至游戏之外的一种非常简单通用的模式。如果你正在部署一个非虚的受保护方法,那么你很可能正在使用与之类似的模式。沙盒模式适用于以下情况:

SubclassSandbox.png
上一篇 下一篇

猜你喜欢

热点阅读