Delphi 灵活运用接口(interface), 隐藏核心代码, 设计低耦合程序.
来源:互联网 发布:电视网络接口怎么安装 编辑:程序博客网 时间:2024/05/16 00:06
原创作品, 如有转载请注明出处.
COPYRIGHT BY cnCharles, ALL RIGHTS RESERVED.
delphi群: 16497064, blog: http://hi.baidu.com/cnCharles
程序详细代码如下
program InterfaceTest;
uses
Forms,
Main in 'Main.pas' {frmMain},
Test in 'Test.pas' {frmTest},
PubIntfs in 'PubIntfs.pas';
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end.
//-----------------------------------------------------------------------------------------------
unit Main;
{
Date : 2007-04-18
Author : cnCharles
Description: 应用程序主界面单元
}
interface
uses
Forms, Dialogs, StdCtrls, Classes, Controls, PubIntfs;
type
TfrmMain = class(TForm, IMainFormTest)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
protected
procedure SayHello;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
uses Test;
{$R *.dfm}
procedure TfrmMain.Button1Click(Sender: TObject);
begin
with TfrmTest.Create(Self) do
Show;
end;
procedure TfrmMain.SayHello;
begin
ShowMessage('I''m a MainForm');
end;
end.
//--------------------------------------------------------------------------------------------------
unit Test;
{
Date : 2007-04-18
Author : cnCharles
Description: 接口测试
}
interface
uses
Forms, StdCtrls, Classes, Controls;
type
TfrmTest = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmTest: TfrmTest;
implementation
uses PubIntfs;
{$R *.dfm}
procedure TfrmTest.Button1Click(Sender: TObject);
begin
(Application.MainForm as IMainFormTest).SayHello;
end;
end.
//-------------------------------------------------------------------------------------------------
unit PubIntfs;
{
Date : 2007-04-18
Author : cnCharles
Description: 对外公开接口
}
interface
const
IID_MainFormTest = '{6E6F8E9C-E147-47DF-95F8-A5861DD8F393}';
type
IMainFormTest = interface
[IID_MainFormTest]
procedure SayHello;
end;
implementation
end.
不 知道你们有没有看明白, 在Test单元中并没有uses(引用) Main单元, 但是但是确可以调用它的 SayHello方法. 在这个Demo中还要明白一个要点, Application.CreateForm 第一次创建派生自TForm 的Form即为程序的主窗体. Application是一个全局变量, 定义在Forms单元中, 只要引用了Forms单元就可以引用Application, Screen对象也与Application一样.
- Delphi 灵活运用接口(interface), 隐藏核心代码, 设计低耦合程序.
- Delphi 灵活运用接口(interface), 隐藏核心代码, 设计低耦合程序.
- interface接口解耦合
- DELPHI指针灵活运用
- 设计模式-高内聚、低耦合
- 设计中低耦合------高内聚
- 设计模式:高内聚,低耦合
- 代码适用性-低耦合案例
- 程序设计之核心“高内聚,低耦合”
- objc@interface的设计:隐藏继承关系中的私有接口
- 设计模式介绍 高内聚,低耦合
- 设计模式介绍 高内聚,低耦合
- 模块化编程设计原则:高内聚,低耦合
- 函数设计应做到低耦合,高内聚
- Android 程序工程的高内聚,低耦合
- .NET核心代码保护策略:隐藏核心程序集
- 高内聚,低耦合 运用到实际项目中
- 低耦合
- 基于WebKit的网络爬虫
- lua
- JQuery里的原型prototype分析
- 如何选择开源许可证?
- mysql使用workbench创建已有表类图
- Delphi 灵活运用接口(interface), 隐藏核心代码, 设计低耦合程序.
- 浅析静态库链接原理
- 取样问题
- 机器学习之Naive Bayes&&python实践
- hdu 2874 Connections between cities LCA || dfs+并查集
- mac下wireshark出现There are no interfaces on which a capture can be done.
- linux中权限(-rwxrwxrwx=777)
- session超时设置
- hive时间函数转换