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;