oop - OO Design Decision: Class build itself from Database or have builder class / factory -
i'm building new application , can't decide way go on question.
should database data oriented classes build database methods like:
class foo { public buildyourselffromdatabaseforid(...) //and overloading constructor etc. public commityourselftothedatabase(); }
or should build database management class / factory handle sql , build objects me, such as:
foo var = dbmanager->createmeafoofromid(id); // make changes var dbmanger->commitchangestofoo(var);
i've worked on projects doing both ways before, can't decide way go on new project , wondered general consensus today?
i mean advantages , disadvantages both ways, more commonly adopted approach on this? established patterns point me towards?
having entity directly contact database violation of separation of concerns - means class doing, in addition own job, database work, not concern.
have factory/builder instead.
a common way hidrate entities database these day through orm - such library mediates between database , object model , deals database interactions on behalf. examples of orms entity framework, nhibernate, dapper , more.
Comments
Post a Comment