UML class diagram:
Sample Code:
[Csharp]
// Base class
Public abstract class Animal
{
Public string Name {get; set ;}
Public abstract void Run ();
}
// Subclass 1
Public class Chicken: Animal
{
Public override void Run ()
{
Console. WriteLine ("Chicken was running ...");
}
}
// Subclass 2
Public class Dog: Animal
{
Public override void Run ()
{
Console. WriteLine ("Dog was running ...");
}
}
// Factory type
Public class AnimalFactory
{
Public Animal CreateAnimal (string animalType)
{
Switch (animalType) // depends on string Classification
{
Case "chicken ":
Return new Chicken ();
Case "dog ":
Return new Dog ();
Default:
Throw new Exception ("Invalid param ...");
}
}
}
// Base class
Public abstract class Animal
{
Public string Name {get; set ;}
Public abstract void Run ();
}
// Subclass 1
Public class Chicken: Animal
{
Public override void Run ()
{
Console. WriteLine ("Chicken was running ...");
}
}
// Subclass 2
Public class Dog: Animal
{
Public override void Run ()
{
Console. WriteLine ("Dog was running ...");
}
}
// Factory type
Public class AnimalFactory
{
Public Animal CreateAnimal (string animalType)
{
Switch (animalType) // depends on string Classification
{
Case "chicken ":
Return new Chicken ();
Case "dog ":
Return new Dog ();
Default:
Throw new Exception ("Invalid param ...");
}
}
}