///
<summary>
///
主维度,文章-Article
///
</summary>
abstract
class
Article
{
private
Scope
scope;
public
Scope
Scopes
{
get
{ return
scope; }
set
{ scope = value;
}
}
public
virtual
void
Publish()
{
scope.PublishImpl();
Console.WriteLine("
发布...");
}
}
//文章的具体子类:
网页
class
WebpageArticle
: Article
{
public
override
void
Publish()
{
Console.WriteLine("
检索网页...");
base.Publish();
}
}
//文章的具体子类:文档
class
DocumnetArticle
: Article
{
public
override
void
Publish()
{
Console.WriteLine("
检索文档...");
base.Publish();
}
}
///
<summary>
///
第二个维度,范围
///
</summary>
abstract
class
Scope
{
abstract
public
void
PublishImpl();
}
//范围的具体子类
class
InsideScope
: Scope
{
public
override
void
PublishImpl()
{
Console.WriteLine("
检索内部人员...");
}
}
//范围的具体子类
class
OutsideScope
: Scope
{
public
override
void
PublishImpl()
{
Console.WriteLine("
检索外部人员...");
}
}
class
MainApp
{
static
void
Main()
{
Article
article
= null;
Console.Write("
请输入
Article
类型,1
代表
WebpageArticle,2
代表
DocumnetArticle
:");
string
articleType
= Console.ReadLine();
switch
(articleType)
{
case
"1":
article =new
WebpageArticle();
break;
case
"2":
article = new
DocumnetArticle();
break;
default:
article = new
WebpageArticle();
break;
}
Scope
scope
= null;
Console.Write("
请输入
Scope
类型,a
代表
InsideScope,b
代表
OutsideScope
:");
string
scopeType
= Console.ReadLine();
switch
(scopeType)
{
case
"a":
scope = new
InsideScope();
break;
case
"b":
scope = new
OutsideScope();
break;
default:
scope = new
InsideScope();
break;
}
article.Scopes
= scope;
Console.WriteLine("
begin publish-------------------------------");
article.Publish();
Console.WriteLine("
end publish---------------------------------");
}
} |