- Get link
- X
- Other Apps
A friend amusingly posted on Facebook a retro photograph of four (4) 'designers' around a cat, with the caption alluding to designing hats for cats, and so I decided to make, somewhat incongruously, an abstract cat factory, which varies by the location of the cat..
Salient Characteristic(s)
namespace DesignPatterns
{
public enum Location
{
Kitchen,
Bedroom,
LivingRoom
}
public enum Amusements
{
String,
Mouse,
Food,
Sleep
}
public abstract class Feline
{
public abstract Feline HereKittyKitty();
}
public class Cat : Feline
{
private Location _Location;
private Feline _Cat = null;
private Amusements _Amusement;
public Cat(Location location)
{
_Location = location;
}
public override Feline HereKittyKitty()
{
switch (_Location)
{
case Location.Bedroom:
_Amusement = Amusements.Sleep;
break;
case Location.Kitchen:
_Amusement = Amusements.Food;
break;
case Location.LivingRoom:
_Amusement = Amusements.String;
break;
default:
_Amusement = Amusements.Mouse;
break;
}
_Cat = new Cat(_Amusement);
return _Cat;
}
private Cat(Amusements fun)
{
}
}
}
Salient Characteristic(s)
- Classes derived from abstract types
- Class creates derived (concrete) classes based on type required
namespace DesignPatterns
{
public enum Location
{
Kitchen,
Bedroom,
LivingRoom
}
public enum Amusements
{
String,
Mouse,
Food,
Sleep
}
public abstract class Feline
{
public abstract Feline HereKittyKitty();
}
public class Cat : Feline
{
private Location _Location;
private Feline _Cat = null;
private Amusements _Amusement;
public Cat(Location location)
{
_Location = location;
}
public override Feline HereKittyKitty()
{
switch (_Location)
{
case Location.Bedroom:
_Amusement = Amusements.Sleep;
break;
case Location.Kitchen:
_Amusement = Amusements.Food;
break;
case Location.LivingRoom:
_Amusement = Amusements.String;
break;
default:
_Amusement = Amusements.Mouse;
break;
}
_Cat = new Cat(_Amusement);
return _Cat;
}
private Cat(Amusements fun)
{
}
}
}
Very good explanation.. this is what I needed
ReplyDelete