本文发表在 rolia.net 枫下论坛using System;
using System.Collections.Generic;
using System.Text;
namespace BuildingWashroom
{
public interface IDoor
{
// if the previous user Lock() the door, the IsLocked would be TRUE
// otherwise, the IsLocked would be FALSE
bool IsLocked { get; }
// if the door is locked, then the Open() would return a FALSE value
bool Open();
// Just close the door, so if two or more people want to come in, when the
// Lock() is not excuted, then, let them come in
void Close();
// Lock the door, so that no more people could come in
void Lock();
// Unlock the door, so that u can get out
void UnLock();
}
public interface IToiletBout
{
// sure, the Toilet should has a door, isn't it?
// if the door is locked, that means someone is using the toilet
// this would be very usefully when the IGenericWashroom.GetNextAvailableToiletBout()
// try to find out the next Available ToiletBout
IDoor Door { get; set; }
// i don't want to say anymore to this, hehe
void LoadShit(object shit);
// after ur working, u have to flush it
void Flush();
}
public interface IPeePool
{
// if someone is using, set it to true, so the IManWashroom.GetNextAvailablePeePool()
// could eazily find out the next Available PeePool
bool IsUsing { get; set;}
// just load
void LoadPee(object pee);
// U have to flush it
void Flush();
}
public interface IGenericWashroom
{
IDoor Door { get; set; }
IToiletBout[] ToiletBouts { get; set; }
IToiletBout GetNextAvailableToiletBout();
}
public interface IManWashroom : IGenericWashroom
{
IPeePool[] PeePools { get; set; }
IPeePool GetNextAvailablePeePool();
}
// A man shoud do three things in a WashRoom
public interface IMan
{
void ToPee(IPeePool peePool, object stuff);
void ToPee(IToiletBout toiletBout, object stuff);
void ToMakeShit(IToiletBout toiletBout, object stuff);
}
// Use it to test
public class TestIt
{
static void Main(string[] args)
{
// now suppose we already had everything we want...
IMan aMan;
IManWashroom aManWashRoom;
// now we have to check if there any Available Toilet Bout in this WashRoom?
IToiletBout toiletBout;
if ((toiletBout = aManWashRoom.GetNextAvailableToiletBout()) != null)
{
// Ok, we now has a Available Toilet Bout, good, en...
// OPEN the door, CLOSE the door, and LOCK the door so that nobody can bother him
toiletBout.Door.Open();
toiletBout.Door.Close();
toiletBout.Door.Lock();
// haha, now we can start making our shit..
aMan.ToMakeShit(toiletBout, new object());
// now it's time to FLUSH
toiletBout.Flush();
// now, unlock the door, open the door and get out, so that next guy could come in
toiletBout.Door.UnLock();
toiletBout.Door.Open();
}
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
using System.Collections.Generic;
using System.Text;
namespace BuildingWashroom
{
public interface IDoor
{
// if the previous user Lock() the door, the IsLocked would be TRUE
// otherwise, the IsLocked would be FALSE
bool IsLocked { get; }
// if the door is locked, then the Open() would return a FALSE value
bool Open();
// Just close the door, so if two or more people want to come in, when the
// Lock() is not excuted, then, let them come in
void Close();
// Lock the door, so that no more people could come in
void Lock();
// Unlock the door, so that u can get out
void UnLock();
}
public interface IToiletBout
{
// sure, the Toilet should has a door, isn't it?
// if the door is locked, that means someone is using the toilet
// this would be very usefully when the IGenericWashroom.GetNextAvailableToiletBout()
// try to find out the next Available ToiletBout
IDoor Door { get; set; }
// i don't want to say anymore to this, hehe
void LoadShit(object shit);
// after ur working, u have to flush it
void Flush();
}
public interface IPeePool
{
// if someone is using, set it to true, so the IManWashroom.GetNextAvailablePeePool()
// could eazily find out the next Available PeePool
bool IsUsing { get; set;}
// just load
void LoadPee(object pee);
// U have to flush it
void Flush();
}
public interface IGenericWashroom
{
IDoor Door { get; set; }
IToiletBout[] ToiletBouts { get; set; }
IToiletBout GetNextAvailableToiletBout();
}
public interface IManWashroom : IGenericWashroom
{
IPeePool[] PeePools { get; set; }
IPeePool GetNextAvailablePeePool();
}
// A man shoud do three things in a WashRoom
public interface IMan
{
void ToPee(IPeePool peePool, object stuff);
void ToPee(IToiletBout toiletBout, object stuff);
void ToMakeShit(IToiletBout toiletBout, object stuff);
}
// Use it to test
public class TestIt
{
static void Main(string[] args)
{
// now suppose we already had everything we want...
IMan aMan;
IManWashroom aManWashRoom;
// now we have to check if there any Available Toilet Bout in this WashRoom?
IToiletBout toiletBout;
if ((toiletBout = aManWashRoom.GetNextAvailableToiletBout()) != null)
{
// Ok, we now has a Available Toilet Bout, good, en...
// OPEN the door, CLOSE the door, and LOCK the door so that nobody can bother him
toiletBout.Door.Open();
toiletBout.Door.Close();
toiletBout.Door.Lock();
// haha, now we can start making our shit..
aMan.ToMakeShit(toiletBout, new object());
// now it's time to FLUSH
toiletBout.Flush();
// now, unlock the door, open the door and get out, so that next guy could come in
toiletBout.Door.UnLock();
toiletBout.Door.Open();
}
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net