# Proxetta

**Proxetta** creates dynamic proxies in run-time, providing efficient\
support for aspects; using developer-friendly syntax.

A proxy class is a class that wraps or extends the target class specified at\
runtime. Proxy **Aspect** contains advice and pointcut rules for\
applying advice. Proxy **Advice** is the code portion of an aspect, i.e.\
the logic that replaces crosscutting concern. A **pointcut** is a set of\
points in the application where advice should be applied, i.e. which\
methods will be wrapped by proxy.

### Proxetta types

**Proxetta** offers 3 different proxy types, that we call: `Proxy`,\
`Wrapper`and `InvokeReplacer`.

#### Proxy <a href="#proxy" id="proxy"></a>

<div align="left"><img src="https://3577005425-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUnrvwkM5q0qRYyQASZ%2F-MUyrdD_TQfrwKsW-u2K%2F-MUysV6VJZczo9JjcG62%2FProxyProxetta.png?alt=media&#x26;token=e2479db5-0d74-4ca9-8685-a8c87e1802cb" alt=""></div>

`ProxyProxetta` is **Proxetta** that extends the target class (*light red*).\
Pointcut methods (*dark red*) are overridden in proxy subclass (*light blue*)\
and called when required from the advice (*dark blue*).

Therefore, instead of working with the target instance, we have proxified\
instance. It will be of the same type as the target (since it’s a\
subclass).

#### Wrapper <a href="#wrapper" id="wrapper"></a>

<div align="left"><img src="https://3577005425-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUnrvwkM5q0qRYyQASZ%2F-MUyrdD_TQfrwKsW-u2K%2F-MUysZizXMyhHTl5K2gY%2FWrapperProxetta.png?alt=media&#x26;token=d0dcc270-b5b9-4f9d-a318-bcde861f2b6b" alt=""></div>

`WrapperProxetta` is *Proxetta* that creates a separate, wrapper class\
(*light blue*) from the target class (*light red*). The wrapper class holds the\
reference of the target class instance. Pointcut methods (*dark red*)\
are called from the wrapper advice methods (*dark blue*). But wrapper\
also delegates call to other target methods.

**Proxetta** offers furthermore several ways how the wrapper behave, and\
if it implements some interface.

#### InvokeReplacer <a href="#invokereplacer" id="invokereplacer"></a>

<div align="left"><img src="https://3577005425-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUnrvwkM5q0qRYyQASZ%2F-MUyrdD_TQfrwKsW-u2K%2F-MUyshGVYrZ3Sth05NXT%2FInvokeProxetta.png?alt=media&#x26;token=d53aed9b-8ee5-43dd-b9bc-d90d2d536d6c" alt=""></div>

Finally, `InvokeProxetta` is a bit different and unique type of proxy. It\
creates a clone class and replaces invocation of target methods in the\
method code with advised method invocation. In other words, it simply\
replaces method calls in the target class.

### Why Proxetta? <a href="#whyproxetta" id="whyproxetta"></a>

First, **Proxetta** is developer-friendly - the syntax is clean and fluent, which makes everyday development easy.

However, what is unique is the way how pointcuts and advices are defined.

*Proxetta* pointcuts are defined in pure Java, no custom proprietary\
notation is used. Therefore, any matching mechanism may be used: regular\
expression, wildcards; configuration might be stored in external (XML)\
files and so on.

**Proxetta's** advices uses a completely different concept than any other AOP\
library. Advices are written *in the same way* as users would write real\
subclass. Instead of using a custom class for accessing proxified method\
and its arguments, they will be **replaced** directly on the usage\
place.

This unique approach makes **Proxetta** fast. Very fast.

The Invocation of replacements proxies is another unique feature of **Proxetta**.

#### Performance test <a href="#performancetest" id="performancetest"></a>

Because of its unique approach for advices definition, *Proxetta* is\
very fast. Compared to one of the most used code generation libraries,\
[CGLIB](http://cglib.sourceforge.net/), the invocation of proxified method is significantly faster.
