Hi all!
The subject of my question doesn't concern Spring and maybe even doesn't concern AOP (
) but nevertheless I thought that this forum would be a good place to start searching an answer (if I was wrong please send me to the right place).
I'll explain by example. Let's take such popular domain object as Country. In fact there are many standards that describe codes for countries and even ISO has offers three code variants: 2char (e.g. US), 3char (e.g. USA) and 3digit (840 for USA). Most applications will be quite happy with 2char code so their Country class would look something like:
Code:
public class Country
{
private String code;
private String name;
// getters/setters ommited
}
But of course, sooner or later, we end up with some use cases (integration some external system EXTSYS) that require 3char or 3digit code. We modify the original code to conform:
Code:
public class Country
{
private String char2Code;
private String char3Code;
private String num3Code;
private String name;
// getters/setters ommited
}
Now at some point in future EXTSYS declares that it's developers realized their mistakes and now the system supports widely used 2char codes. To save memory, processor time etc we would have to rollback to our previous class and that would require a lot of manual work.
Now to the point. My idea is to somehow adopt AOP to enrich domain model with some sort of aspects, so that each new code system in our example would be a separate 'aspect' that can be easily maintained and separated.
Maybe the example is funny, but consider the following situation: you develop some application and tune it for different clients. So you have a base version, and some client specific versions that are enriched to conform to client's requirements with some extra classes. Let's assume this is an e-shop. Now client A wants to add a photo to each one of his Products, while client B doesn't need it. So we need to
1. somehow enrich Product class for client A to contain byte[] image
2. client's B build must not include this
3. inheritance won't do, because we would have to change the functionality that creates a Product when "New Product" is clicked somewhere, and that is impossible because it is a part of main functionality shared by all clients