Domain Entities
mifos has several entities. Some are in form of <XYZ>Entities, <XYZ>BOs. Some are entities that are used for localization purpose, in turn using lookup entities. Some entities are just enums. (TODO: should adopt better naming for such enums)
- org.mifos.accounts.fees.business.FeeBO* is one such entity. And precisely what we do not want in an entitiy. It has persistence code within. Calls multiple persistence classes (like OfficePersistence, MasterPersistence etc), calls these persistence classes from constructors and other methods. if/elses, often obfusticating business concepts, carries around probably old redundant code and concepts (e.g FeeLevel). Throws various types of exceptions. It also has multiple constructors, many of which are only to help testing, which is a sure sign that something is not right!
The new platform entities should be simple POJOs, devoid of persistence.
org.mifos.accounts.fees.entities.FeeEntity is an effort towards moving to new platform practices.
Entities should preferably be immutable. Sometimes it may not be possible to make new entities entirely immutable, as many such entities require additional relational entities. For example, FeeFrequency is a relational entity for Fee and a fee can't be created without one frequency. FeeFrequency is associated with a meeting, payment etc which fee entity directly has no relation to. Under such situations, a setter method (e.g. FeeEntity.setFeeFrequency()) maybe useful and only be used from specific DomainServices.
It is not that new platform codebase can't reuse older legacy entities. FeeEntity was created to get rid of FeeBO, and such new entity creation would probably result in cascading effect of other relational entities like FeeFrequencyEntity, FeeLevelEntity. And also towards subclasses like RateFeeEntity and AmountFeeEntity. However, the new platform code reuses whole lot of other entities fetched through HibernateUtil like GLCodeEntity, OfficeBO, MeetingBO etc. So rule of thumb for older entity reuse: 1) Do not intermix with <XYZ>BOs unless only for retrieval purposes. 2) Relational entities do not refer back to older entities. for example FeeFrequencyEntity in turn uses FeeBO for bi-directional relationship setup in Hibernate.