Re: Kinds of methods



Responding to Daniel T....

I just wrote this up for someone on one of the C++ newsgroups. Any comments?

Member-functions can be categorized into one of 4 types:

modifier - a member-function that can change the external state of the object. IE calling a modifier could cause one or more other member-functions of the object's class to behave differently or produce different output when called on this object, than they otherwise would before the modifier was called.

producer - a member-function that creates an object for the caller to use, or sets the state of an object the caller passed in.

accessor - a member-function that gives the caller a pointer/reference to one of the object's member-variables such that modifying the value contained in the pointer/reference will change the state of the object as if a modifier was called.

provider - a member-function that gives to the caller a pointer/reference to one of the object's member-variables such that modifying the value contained in the pointer/reference will not change the state of the object that the member-function was called on.

In C++, we also have a special purpose modifier member-function...

destructor - a designated "last call". Class designers, can be assured that this member-function will be the last one called on an object, it will be called exactly once, and that it will be called for all objects.

The abstract action languages used for translation employ a similar breakdown that may be of interest:

Read Accessor: basically a synchronous getter for knowledge responsibilities. The knowledge need not be implemented as a state variables (attributes). Multiple attributes can be accessed. Always returns by value, hence no need for your provider.

Write Accessor: basically a synchronous setter for knowledge responsibilities. The knowledge need not be implemented as state variables. Multiple attributes can be accessed.

Create Accessor: basically your producer. Creates object instances and instantiates their relationships.

Delete Accessor: basically your destructor.

Transformation: a synchronous service that provides some transformation of knowledge (e.g., Matrix.transpose()). It is limited to operating only on passed data and the values of the owning object's attributes. This probably maps closely to your modifier.

Test: a synchronous service that provides some test of knowledge and returns TRUE/FALSE. Used for things like condition event generation. Encapsulates the notion that all flow of control decisions should be "owned" by a single object.

Link Accessor: used to dynamically instantiate relationships. similar idea to your provider except it's not a copy maker.

Unlink accessor: user to dynamically deinstantiate relationships. [Note that link/unlink help ensure that relationship navigation is orthogonal to class semantics.]

Action: implements a particular behavior responsibility. These must be logically indivisible at the object's level of abstraction. Since all behavior collaborations at the AAL level are asynchronous, an action cannot depend in any way on other actions (i.e., it can only invoke Accessors, Tests, and Transformations). In the translation world, these are always state machine actions, hence the name.

An important point is that these are really defined around what the method can and cannot do. For example, an Action cannot invoke other actions or hard-wire flow of control tests, but it can invoke any of the other synchronous services. Similarly, a Transformation may not instantiate objects, implement behavior responsibilities, or hard-wire flow of control tests. That separation of concerns results in more methods and message traffic but it also results in very robust applications.


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH



.



Relevant Pages

  • Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... or sets the state of an object the caller passed in. ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Re: Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... Destructor is different in the way of its composition. ... Constructor has an output parameter of the object's ...
    (comp.object)
  • Re: Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... or sets the state of an object the caller passed in. ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Re: Kinds of methods
    ... a modifier since it never returns to the caller but does change the external ... modifier - a member-function that can change the external state of the ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)
  • Re: Kinds of methods
    ... modifier - a member-function that can change the external state of the ... IE calling a modifier could cause one or more other ... or sets the state of an object the caller passed in. ... accessor - a member-function that gives the caller a pointer/reference ...
    (comp.object)