coding style - Best way to use of setters in OOP -



coding style - Best way to use of setters in OOP -

let's assume have class , whenever set attributes bla, foo (which can set externally , internally) want phone call method of class, let's phone call onchangefunction().

would way phone call onchangefunction() when setting internal values directly, e.g.

function somefunction() // calculations here ... this.bla = some_value; this.onchangefunction() end

or improve set variables bla , foo using internal setter-methods because there action triggered , more arranged code.

i go step further: let's don't need extern setter can called outside (access type = public), still invent private setter same approach , utilize setter because of triggered set-action? edit: mean following: if not have public setter (because there should not public access set variable, because it's internal variable) still have setter private-only because of triggered action thing?

thanks in advance!

i think in long term much less error-prone utilize setter, , phone call onchangefunction() within setter.

you don't specify programming languages have in mind, languages allow 1 define "property" looks info fellow member calls function when effort made alter it. see, example, property et al in python.

as sec question, don't think there's wrong having private setter.

oop coding-style setter

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -