c# - How to avoid getters in aggregate internal collection? -


i'm trying follow advice whereby "using getters/setters in classes evil". so, have aggregate class invoice following signature:

public class invoice{     iset<line> _lines;     public void changelineamount(int lineid, double newamount){                //your answer here            }     } 

how can find specific line change, if line class has no getters?

reason behind phrase "using getters/setters in classes evil" in matter of ddd getters , setters not representing ul(ubiquitous language) , leading anemic entities. if in ul there "i need amount of line", can create getter name according ul, like: invoice.lineamount(lineid).

inside of method can access property charlesnrice answered. if feel need special treatment reading/setting lines, can create private getter use inside of domain logic methods.

update:

getters , setters needed in first place because later in project could've want add additional validation/converting before setting/getting property, without have find every piece of code accesing property , change it. getter/setter access property in 1 place change code in 1 place - easier maintain. since in ddd must use domain logic methods, don't access properties directly anywhere outside of given entity, don't have use getters , setters. domain methods invoice.lineamount(lineid) working getters, going along ul ok. consider create real getters/setters internal use if see accesing property in few places in entity class.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -