Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə36/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   32   33   34   35   36   37   38   39   ...   47
Java Interview Guide

Aspect-Oriented Programming
Core Concerns vs Cross-Cutting Concerns
A core concern is a unit of work that contributes to the business logic of an
application, such as storing records in a database or generating reports. A cross-
cutting concern is a feature that spans across core concerns and supports
an application, such as logging or caching.


Aspect-Oriented Programming
Aspect-oriented programming (AOP) isolates cross-cutting concerns through the
use of aspects. Aspects work by targeting a method, called a join point,
and surrounding it with additional code. Join points are determined by an
expression called a pointcut. For example, in order to find the slowest method
in an application, you could declare a pointcut that targets all public methods and
compare the time before and after each join point executes.


Proxy Objects
A simple way to implement aspect-oriented programming is through the use
of proxy objects. A proxy is a wrapper that provides additional functionality
to an object of interest. Proxies can be implemented through interfaces
or inheritance.


Interface Proxies
An object that implements an interface can be proxied by another class that
implements the same interface. For example, in order to log every method call
on an ArrayList, you could create a ProxyList class that implements
List
and delegates every method to a private ArrayList. Each delegated
method provides a join point that can be surrounded by logging code.
This proxy could be passed to any method that accepts a List. However,
one limitation of interface proxies is that any self-invoked method inside the
composed object will not be proxied. For example, if the remove() method
in ArrayList internally calls the get() method, that call will not be logged
because the join point will never be invoked.



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   32   33   34   35   36   37   38   39   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin