Question might be silly for experts but please help me with pointers if it is already solved somewhere.
Interview Question : "Design class diagram in best possible way"
-
You need to design a game "SuperHeroes".
-
Super hero examples are Batman, Spider-Man, Thor, Hal Jordan, Wonder Woman, Captain America .... n
-
Spiderman can jump, crawl, generateFire ....n
- Batman can jump, crawl, fly .... n
-
Thor can swim, fly .... n
-
There can be millions of behaviour.
-
There can be millions of Super heroes.
-
Some have few behaviours common in them and some specific to hero.
- Design should be flexible enough to add behaviours to the super heroes
Important point to focus was told that "System should be scalable"
I tried twisting decorator pattern to accommodate problem requirements but was failing at many places, also I have to make many interfaces for this, so scalability was questionable.
I tried another approach as Writing all behaviours in one class(If require will classify behaviours in respective classes, kind of utility class which will have all implementations of behaviours). and an Spiderman class which will have list of allowable Behaviours(kind of enum). and it is allowed to call methods from behaviour utility only if such behaviour is allowed in list. I think it is not a good approach.
Please help me with best way to achieve this.
Aucun commentaire:
Enregistrer un commentaire