Applying AOP to implement log function in Delphi

Source: Internet
Author: User
Tags aop

AOP is now very hot, there are many support AOP framework on the Internet, for Delphi also have MEAOP. But I think these frameworks are too complicated.

Now there is a system that is basically almost over, and of course there is no AOP framework in use. Is there a little bit of the benefit of AOP for such a system?

The project team proposes the need to include logging on existing systems. Let's take a look at how I can achieve this function.

AOP Brief description

Based on the online interpretation of AOP, it has the following characteristics:

1, the general function from the relevant classes separated from;

2, can make many classes share a function, once the function changes, do not have to modify a lot of classes, as long as the modification of this function can be.

The core of AOP is to keep crosscutting concerns separate.

Log function

This is a more typical MIS system, now the coding is basically over. However, a developer receives a cumbersome and seemingly low-tech task-implementing logging. This developer is himself.

Although not difficult, but still design it, who let me be a self-proclaimed high level of programmers.

A design diagram is done. An interface Ilog is designed to encapsulate the details of the log implementation. Module A b c only need to use the interface Ilog. It satisfies the principle of xxx object-oriented design. It's perfect!

Brew a cup of tea and start writing code to achieve this simple and huge task.

Start coding!

Tlog,ilog implementation is relatively simple, in this omitted not to talk about. Modify the code of the previous module slightly, passing the Ilog interface into each module.

Then you just need to implement the log function call.

Module A:

procedure TModule1.acAction1Execute(Sender: TObject);
begin
……
Flog.LogCommand(“模块甲 操作一”);
end;
procedure TModule1.acAction2Execute(Sender: TObject);
begin
……
Flog.LogCommand(“模块甲 操作二”);
end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.