My Composite in C#

婉凝紫

婉凝紫

2016-01-29 12:48

My Composite in C#,My Composite in C#

//MyComposite
using System;
using System.Collections;
//----------------------------------Class FileElement
abstract class CFileElement
{
//Fields
protected string name;

public CFileElement(string name)
{
this.name=name;
}
public abstract void Add(CFileElement e);
public abstract void Remove(CFileElement e);
public abstract void Display();
};
//Class CFile
class CFile:CFileElement
{
public CFile(string name):base(name){}

public override void Add(CFileElement e)
{
Console.WriteLine("Can't add any files under a file!");
}
public override void Remove(CFileElement e)
{
Console.WriteLine("Can't remove any sub files!");
}
public override void Display()
{
Console.WriteLine(this.name);
}
};
//Class CFolder
class CFolder:CFileElement
{
private ArrayList children =new ArrayList();

public CFolder(string name):base(name){}
public override void Add(CFileElement e)
{
children.Add(e);
}
public override void Remove(CFileElement e)
{
children.Remove(e);
}
public override void Display()
{
Console.WriteLine(this.name);
foreach(CFileElement e in children)
{
e.Display();
}
}
};
//----------------------------------Class Element
//TestApp
class TestApp
{
public static void Main(string[] args)
{
CFolder root = new CFolder("Z:/");
CFolder afolder=new CFolder("Games/");

afolder.Add(new CFile("cstrike.exe"));
root.Add(afolder);
root.Display(); while(true); }};
展开更多 50%)
分享

猜你喜欢

My Composite in C#

电脑网络
My Composite in C#

无废话C#设计模式之十一:Composite

编程语言 网络编程
无废话C#设计模式之十一:Composite

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

展现C#(1):C#简介

ASP
展现C#(1):C#简介

掌握 C#

电脑网络
掌握 C#

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

C#简介

编程语言 网络编程
C#简介

Beginner with C#

编程语言 网络编程
Beginner with C#

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

在FLASH中弹出网页窗口

在FLASH中弹出网页窗口

Jboss下配置EJB

Jboss下配置EJB
下拉加载更多内容 ↓