- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Facade
- {
- private Func1 field1;
- private Func2 field2;
- public Facade()
- {
- field1 = new Func1();
- field2 = new Func2();
- }
- public void Method()
- {
- field1.Method();
- field1.Method1();
- field2.Method();
- }
- public void Method1()
- {
- field2.Method();
- field2.Method1();
- field1.Method();
- }
- }
- class Func1
- {
- public void Method()
- {
- Console.WriteLine("功能类1的方法1");
- }
- public void Method1()
- {
- Console.WriteLine("功能类1的方法2");
- }
- }
- internal class Func2
- {
- public void Method()
- {
- Console.WriteLine("功能类2的方法1");
- }
- public void Method1()
- {
- Console.WriteLine("功能类2的方法2");
- }
- }
- class Client
- {
- public static void Main()
- {
- Facade f = new Facade();
- f.Method();
- f.Method1();
- Console.Read();
- }
- }
- }

本文通过C#编程语言实例,展示了如何利用面向对象编程原则创建组件,并通过组件间的方法调用实现功能交互。重点阐述了组件的定义、初始化、方法调用及其在实际场景中的应用。
2625

被折叠的 条评论
为什么被折叠?



