News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ tip - Handling functions with large numbers of args

Started by ben2ong2, October 07, 2006, 03:57:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

PROBLEM: Users of C++ often run into functions which have large numbers
of parameters. This often occurs gradually over time. In addition,
later changes often add arguments with default values. The result becomes
unweildy and difficult to maintain.

One technique for handling this is called "reification" - making an object
out of the function. The stucture of this object mirrors the function
and its arguments quite nicely.

The function arguments are mapped into object data members, and the function
itself becomes a method of the object.


A partial list of advantages of this technique are:

   - the object state can be completely set as part of the constructor,

   - clients can use access methods to "tweak" the object state prior to
     invoking the method,

   - code maintainers are no longer constrained by the first appearanc
     of a default value for an argument,

   - multiple constructors can provide different initial states, and

   - overloading the single method can provide different modes of using
     the function.


You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login