Uniform Access Principle - UAP Example

UAP Example

If the language uses the method invocation syntax it may look something like this.

//Assume print displays the variable passed to it, with or without parens //Set Foo's attribute 'bar' to value 5. Foo.bar(5) print Foo.bar

When executed, should display :

5

Whether or not Foo.bar(5) invokes a function or simply sets an attribute is hidden from the caller. Likewise whether Foo.bar simply retrieves the value of the attribute, or invokes a function to compute the value returned, is an implementation detail hidden from the caller.

If the language uses the attribute syntax the syntax may look like this.

Foo.bar = 5 print Foo.bar

Again, whether or not a method is invoked, or the value is simply assigned to an attribute is hidden from the calling method.

Read more about this topic:  Uniform Access Principle