没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > jseed |
jseed
|
0 | 0 | 25 |
贡献者 | 讨论 | 代码提交 |
jSeedRemoving the tedious so you can get the serious stuff done
SummaryjSeed is a framework that reduces coding efforts by removing boiler plate code. It does this by creating concrete classes from interfaces and abstract classes through the use of code injection. Using annotations and abstract methods jSeed injects the code, creating a new concrete class.
Some of the common boiler-plate code jSeed removes are:
Setter/Getter or Mutator/Accessor methods by defining default behavior Logging logging a method being called Synchronization allowing abstract method to enforce synchronization Factory methods using lazy initialization of a single instance Dependency Injection to reduce the need of having to define each property DescriptionjSeed is a code injection framework which reads your coding intentions based on your template and does the coding work for you. It does this by looking at annotations on methods, classes, and fields and from the annotations writes the code behavior needed to make them function.
For example, when writing the code for beans, it's very common to define setter and getter logic which takes in a property to be set within the bean instance, and read from later. This boiler plate code which needs to be written can easily be done automatically. When the needs change and the bean requires support for property change listeners, instead of modifying the code on all your fields you can simply define the method signatures for adding and removing a property change listener and let jSeed do the rest. No need to test the injected code since the use of annotations along with validators you can be sure of its behavior.
jSeed can then be used to write the repetitive code for you that developers neither desire nor have the time to write on their own. Thus, when writing your beans all that is necessary to define is the signatures of the methods, the rest of the code will be fleshed out at runtime. This simplifies your code base and brings focus to the code which matters which is the actual objects behavior.
A possible bean implementation could be the following:
@Bean
public abstract class Person{
public abstract void setName(String name);
public abstract String getName();
public abstract void setPhoneNumber(PhoneNumber pn);
public abstract PhoneNumber getPhoneNumber();
public abstract void setAddress(Address a);
public abstract Address getAddress();
}The code above is specifying a person bean class. The code that follows shows how you can instantiate the bean which has fully functional code supported.
Seed.grow(Person.class);
Person person = Seed.getInstance(Person.class);Taking the concept a little further we can add Property Change Listener support to be notified whenever the setValue method is called:
@Bean
public abstract class Person {
...
void addListener(PropertyChangeListener l);
void removeListener(PropertyChangeListener l);
}We can also inject lazy initialization of an instance, by using the registry Seed to register the component needed:
@Bean
public abstract Person{
...
public abstract Contract getContract();
protected abstract void setContract(Contract contract);
@Factory
public ContractService getContractService();
public void createContract() {
Contract contract = getContractService().createContract();
setContract(contract);
}
}
// Some calling code
Seed.grow(IContractService.class, new USContract()); // a concrete class
Seed.grow(Person.class);
// It can then be used as follows
Person person = Seed.getInstance(Person.class);
bean.createContract();The only difference here is that now Person is using the abstract class to define behavior in the bean to manipulate some of it's internal state. This mixing of ideas allows for a lazy style of coding which removes the need to specify all the details.
StatusCurrently this project is in a prototype state. But feel free to try the current release of jSeed