Wednesday, May 27, 2009

Model a fighter academy with Factory Method and Abstract Factory design pattern

In my previous posts, I have modeled a fighter and a fighter's body conditions, now I will model the academy which trains the fighters.

Below you will find abstract classes and concrete classes for a fighter training system. You will find classes for regional fighter academies along with classes for fighters a academy can train. Each regional academy can decide how they will train the fighters.

First of all, a fighter academy is just an abstract brand, such as ShaoLin Temple, Karate Institute or Aikido Dojo... A fighter get trained under ShaoLin temple only told us it should have some characters and qualities, but did not restrict how they should get trained. In another words, the detailed training plan is the decision of a specific regional ShaoLin Temple, no matter it's ShongShan mountain ShaoLin Temple or New York City ShaoLin Temple. We model this with factory method design pattern. While abstract class FighterAcademy guaranteed to return a qualified fighter, the concrete class NYCShaoLinTemple make it happen by making the actual training plan in the method trainFighter().

As a common challenge all brands face, we need a quality control mechanism. For example, Jack wants to open an ObjvillKarateInstitute today, he can't claim his institute to be a qualified fighter academy until he hires a licensed fighter. Only through the licensed fighter, we can call method TrainSpeed(), TrainPower(), TrainFlexibility(), TrainReflection(), TrainStagama(). Here the abstract factory come into play.

No comments:

Post a Comment

meta.ai impression

Meta.ai is released by meta yesterday, it is super fast you can generate image while typing! You can ask meta.ai to draw a cat with curvy fu...