c# - Is it normal practise to have getters which call private methods in API design? -
is common, in api design, this:
public readonlycollection getcollection { { // get's read collection here... } } in body of get, calls private method fills collection. expose one, consistent object clients. thing confuses me if right make class , members static? after all, returning object class immutable (i keep thinking immutable class should static?). aware static not insinuate stateless. right in thinking static right centralised 1 entity (e.g. company details)?
thanks
avoid static - trait of procedural programming. use utility methods , widely-accessibly constants.
and no - static != immutable, have nothing in common. static global state, not thread-safe, , can't have more 1 occurrence of static data in application.
immutable means object instance cannot change internal state. string example - once construct it, cannot change it. has nothing static-ness, though.
as first question - fine getter expose internal collection, read-only copy of it.
Comments
Post a Comment