Atom pattern is combination of Proxy/Facade/Wrapper pattern. Main idea of Atom pattern reduce complexity of third party libraries in your business code.
-
Difficult to change one third party library to other library in big project,
-
Some of third party libraries is very complicated (it have a lot of type, class and method), but you need only small part of this in your project,
-
Difficult to add logging, debugging, change methods of third party libraries and so on,
-
High coupling between your code and third party libraries
-
You can't use Dependency injection with a third party library (if library author is not provide DI support)
Do not use third party libraries directly, but add to your project some Proxy/Atoms (in separate module or package) and call only Atom from your project.
Common approach:
Atom-pattern approach:
@Atom(Document.class)
@Molecule({ElementAtom.class, ListAtom.class})
@Contract("Provide information about HTML pages")
public class DocumentAtom {
private final Document original;
@Contract("Should returns elements according this CSS Query")
public ListAtom<ElementAtom> select(String cssQuery) {
ListAtom<ElementAtom> result = ListAtom.create();
result.addAll(original.select(cssQuery).stream().original(ElementAtom::getAtom).collect(ListAtom.getCollector()));
return result;
}
// -------------- Just boilerplate code for Atom -----------------
@BoilerPlate
private DocumentAtom(Document original) {
this.original = original;
}
@BoilerPlate
static DocumentAtom getAtom(Document original) {
return new DocumentAtom(original);
}
}
Description: All Exceptions (checked or unchecked) from a third party libraries classes catch in Atoms and throw as AtomException.
For example:
public boolean createNewFile() {
try {
return original.createNewFile();
} catch (IOException exp) {
throw new IOAtomException(exp);
}
}
Usage:
-
Easy debug business logic in your application, because you can split exceptions in your own classes and exceptions from a third party libraries,
-
Reduce code to catch checked exception in your business (if you need),
In progress
In progress
In progress
In progress
In progress