forked from litiansum/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
孤鸿 夜
committed
Oct 22, 2017
1 parent
bae8072
commit 5b00892
Showing
9 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Proxies.GiveGift | ||
{ | ||
/// <summary> | ||
/// 女孩类 | ||
/// </summary> | ||
class Girl | ||
{ | ||
public Girl(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
private string _name; | ||
|
||
public string Name { get => _name; set => _name = value; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Proxies.GiveGift | ||
{ | ||
/// <summary> | ||
/// 送礼接口 | ||
/// </summary> | ||
interface IGiveGift | ||
{ | ||
void GiveDolls(); | ||
void GiveFlowers(); | ||
void GiveChocolate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Proxies.GiveGift | ||
{ | ||
/// <summary> | ||
/// 代理类 | ||
/// </summary> | ||
class Proxy : IGiveGift | ||
{ | ||
Pursuit gg; | ||
|
||
public Proxy(Girl mm) | ||
{ | ||
gg = new Pursuit(mm);//通过代理,实例化追求者,Girl并不知道 | ||
} | ||
|
||
public void GiveChocolate() | ||
{ | ||
gg.GiveChocolate(); | ||
} | ||
|
||
public void GiveDolls() | ||
{ | ||
gg.GiveDolls(); | ||
} | ||
|
||
public void GiveFlowers() | ||
{ | ||
gg.GiveFlowers(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Proxies.GiveGift | ||
{ | ||
/// <summary> | ||
/// 追求者类 | ||
/// </summary> | ||
class Pursuit : IGiveGift | ||
{ | ||
Girl girl; | ||
|
||
public Pursuit(Girl girl) | ||
{ | ||
this.girl = girl; | ||
} | ||
|
||
public void GiveChocolate() | ||
{ | ||
Console.WriteLine(girl.Name + "送你巧克力"); | ||
} | ||
|
||
public void GiveDolls() | ||
{ | ||
Console.WriteLine(girl.Name + "送你洋娃娃"); | ||
|
||
} | ||
|
||
public void GiveFlowers() | ||
{ | ||
Console.WriteLine(girl.Name + "送你鲜花"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/**** | ||
* 代理模式:为其他对象提供一种代理以控制对这个对象的访问。 | ||
* 应用: | ||
* 1. 远程代理,也就是为一个对象在不同的地址空间提供局部代表。这样可以隐藏一个对象存在与不同的地址空间的事实; | ||
* 2. 虚拟代理,是根据需要创建开销很大的对象。通过它来存放实例化需要很长时间的真是对象; | ||
* 3. 安全代理,用来控制真实对象访问时的权限。 | ||
* 4. 智能引用,是指当调用真实对象时,代理处理另外的一些事。 | ||
* | ||
* | ||
*/ | ||
|
||
|
||
using Proxies.GiveGift; | ||
using System; | ||
|
||
/// <summary> | ||
/// 代理模式实例,追求者通过代理给女孩送礼物 | ||
/// </summary> | ||
namespace Proxies | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
|
||
Proxy proxy = new Proxy(new Girl("小红")); | ||
|
||
proxy.GiveChocolate(); | ||
proxy.GiveDolls(); | ||
proxy.GiveFlowers(); | ||
|
||
Console.ReadKey(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.