oop - Required attributes in Smalltalk -


i writing classes in pharo smalltalk, assume question valid other smalltalk implementations.

i know way enforce instances specific attributes provide class method instance creation, , suggesting use class creation method. user know new or basicnew can used anytime.

i thought invalidating new , basicnew raising exception, seems drastic measure, giving require create instances debug example.

is there library or mechanism enforce specific attributes completed?

there not. , good.

here approaches might follow though:

  1. make sure objects valid providing validations them. broad topic validation framework 1 able examine objects , somehow make explicit rules fail honor.

    depending on doing, might restrict validations gui, when objects born or modified. more sophisticated approach, however, should allow object decide whether valid or not (in given context).

  2. exclude individual setters instance-side protocol. provide multiple keyword setters fail if missing or inappropriate. means provide methods point >> #x:y: not poit >> #x: or point >> #y:.

    as example suggests, find hard take practice @ full extent because basic classes don't follow style. note practice require kind of validation because checking notnil naïve.

  3. relax , nothing until need arrives addressing these kinds of issues.

    in other words pospone problem until software evolved enough call attention way objects created , change.

the reason claim things way because smalltalk, having traditionally favored openness on security, has facilitated , encouraged people experiment, in "wrong" way. every feature aimed @ preventing objects being broken, sooner or later stop repairing them. more importantly, consume lot of energy otherwise applied more productive ends.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -