ooppropertieslanguage-designwriteonly

When designing an OO language, should I avoid write-only properties?


I am designing an object-oriented programming language for the purpose of learning. The language has properties, like this:

Class Fruit:
  Property ReadWrite Float weight
  Property WriteOnly Integer someWriteOnlyProperty # <-- avoid?

Should I add the option for write-only properties or will this only lead to bad design decisions in programs using this language?


Solution

  • By all means design write-only properties - just be aware they are of limited use (if you are only going to write to it and never expose it, why have a property?).

    Might as well use a simple method instead. This will reduce any confusion of those using your code.


    Java and .NET do have write only properties, so there are precedents.