Uniform Access Principle - Explanation

Explanation

The problem being addressed by Meyer involves the maintenance of large software projects or software libraries. Sometimes when developing or maintaining software it is necessary, after much code is in place, to change a class or object in a way that transforms what was simply an attribute access into a method call. Programming languages often use different syntax for attribute access and invoking a method, (e.g. obj.something versus obj.something). The syntax change would require, in popular programming languages of the day, changing the source code in all the places where the attribute was used. This might require changing source code in many different locations throughout a very large volume of source code. Or worse, if the change is in an object library used by hundreds of customers, each of those customers would have to find and change all the places the attribute was used in their own code and recompile their programs.

Going the reverse way (from method to simple attribute) really wasn't a problem, as one can always just keep the function and have it simply return the attribute value.

Meyer recognized the need for software developers to write code in such a way as to minimize or eliminate cascading changes in code that result from changes which convert an object attribute to a method call(or vice versa). For this he developed the Uniform Access Principle.

Many programming languages do not strictly support the UAP but do support forms of it. Properties, which are provided in a number of programming languages, provide a way to invoke a method of an object while using the same notation as is used for attribute access. The separate method invocation syntax is still available.

Read more about this topic:  Uniform Access Principle

Famous quotes containing the word explanation:

    There is no explanation for evil. It must be looked upon as a necessary part of the order of the universe. To ignore it is childish, to bewail it senseless.
    W. Somerset Maugham (1874–1965)

    Young children constantly invent new explanations to account for complex processes. And since their inventions change from week to week, furnishing the “correct” explanation is not quite so important as conveying a willingness to discuss the subject. Become an “askable parent.”
    Ruth Formanek (20th century)

    Auden, MacNeice, Day Lewis, I have read them all,
    Hoping against hope to hear the authentic call . . .
    And know the explanation I must pass is this
    MYou cannot light a match on a crumbling wall.
    Hugh MacDiarmid (1892–1978)