|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Basic
{
/// <summary>
///
/// </summary>
class RoomFactory
{
/// <summary>
///
/// </summary>
private static RoomFactory s_RoomTypes;
/// <summary>
/// Not allow to create the instance of
/// the class
/// </summary>
private RoomFactory()
{ }
/// <summary>
/// Singleton Pattern for RoomFactory
/// </summary>
internal static RoomFactory Singleton
{
get
{
if (s_RoomTypes == null)
{
s_RoomTypes = new RoomFactory();
}
return s_RoomTypes;
}
}
/// <summary>
/// Noob Implementation of Factory Pattern
/// Violates the open/closed principle
/// Returns the corresponding room type
/// </summary>
/// <param name="roomType"></param>
/// <returns></returns>
internal IRoomType GetRoomType(RoomTypes roomType)
{
IRoomType room = null;
switch (roomType)
{
case RoomTypes.AC:
room = new ACRoom();
break;
case RoomTypes.Basic:
room = new BasicRoom();
break;
case RoomTypes.NonAC:
room = new NonACRoom();
break;
}
return room;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.