I'm learning about design patterns and currently a small task is to create a tiny game (just some simple strings to output) with one main character (Name: SuperVan).
The SuperVan can change it's color, it's wheels, be smaller and bigger. The SuperVan can only do one thing at the time.
Design pattern wise, how would you go on about this task? I was thinking about using a Singleton design pattern (creational pattern).
In the assignment we have to have the following output:
- Hey, its me! SuperVan
- I'm a small SuperVan!
- I'm a tall SuperVan!
- My color has changed, wow!
How would a more professional programmer go on about this task? Would love to hear your thoughtprocess.
I'm using this site: https://sourcemaking.com/design_patterns/creational_patterns to learn about design patterns.
Thank you
Example of a singleton class I had in mind for a tall SuperVan:
// Should be threadsafe this way
public sealed class Tall {
private static volatile Tall instance;
private static object syncRoot = new Object();
private Tall() {}
public static Tall Instance {
get {
if (instance == null) {
lock (syncRoot) {
if (instance == null) {
instance = new Tall();
}
}
}
return instance;
}
}
public static void GetInfo() {
Console.WriteLine("Tall!");
}
}
Aucun commentaire:
Enregistrer un commentaire