|
AOP and IoC |
|
cut across multiple components in a system.
AOSD makes it possible to modularize and
separate these services and then apply them
declaratively to the components and we can
focus on our own specific concerns. For instance
if we talk of spring framework, there aspects
are wired into objects in the spring XML file in
the same way as JavaBean does. This process
is also known as ‘Weaving’.
In a typical object-oriented
development approach the developer might implement
logging functionality by putting logger statements in all
your methods and Java classes. In an AOP approach you would instead modularize the
logging services and apply them declaratively
to the components that required logging. The
advantage, of course, is that the Java class
doesn’t need to know about the existence of
the logging service or concern itself with any
related code. As a result, application code
written with Spring AOP is loosely coupled.
Lets do a comparison of OOP’s model
with an AOP model, diagrammatically:
Here, the OOPs model shows that a source codeis
directly compiled to an executable form. On
the other hand, the AOP model depicts the flow
such that the source code in the OOP model
gets compiled with the aspects such that it
modifies the behavior of the OOPs model and
modularizes the crosscutting concerns.
Among the most OOPs languages, Java is a
true Object-Oriented Programming language with a best
support for AOP techniques. There are multiple tools
available to support AOP with Java, few of them are
shown below: |
|
· AspectJ
· AspectWerkz
· Hyper/J
· JAC
· JMangler
· MixJuice
· PROSE
· ArchJava
II. IoC: Inversion Of Control
“The IoC pattern enables better software design
that facilitates reuse, loose coupling, and easy
testing of software components.”
The basic concept of the Inversion of Control
pattern (also known as dependency injection)
is that you do not create your objects but
describe how they should be created. You avoid
connecting components and services together
in your code. Instead the configuration files
are used to describe the services needed by a
component .
The Inversion of Control (IoC) pattern, also
known as Dependency Injection, has recently
become popular in the JEE community. Several
open source projects, including Spring,
PicoContainer, and HiveMind, use the IoC pattern
to develop lightweight J2EE Containers. IoC is
not a new concept, however. It has been around
for several years now. Using object-oriented
design principles and features such as interface,
inheritance, and polymorphism, the IoC pattern
enables better software design that facilitates
reuse, loose coupling, and easy testing of
software components.
Inversion of Control (IoC) means that objects
do not create other objects on which they rely
to do their work. Instead, they get the objects
that they need from an outside source (for
example, an xml configuration file).
Dependency Injection (DI) means that this is
done without the object intervention, usually
by a framework component that passes constructor parameters and set properties.
|
|
Nov 2007 | Java Jazz Up | 6 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 Download PDF |
|
|
|
|
|
|
|
|
|