What is an action class?



What is an action class?..

Answer / ritesh pal

The simplest and most obvious way to specify an action in C++ is to write a function. However, if the action has to be delayed, has to be transmitted 'elsewhere' before being performed, requires its own data, has to be combined with other actions, etc then it often becomes attractive to provide the action in the form of a class that can execute the desired action and provide other services as well.

Manipulators used with iostreams is an obvious example.

Explanation:
A common form of action class is a simple class containing just one virtual function.
class Action
{
public:
virtual int do_it( int )=0;
virtual ~Action( );
}
Given this, we can write code say a member that can store actions for later execution without using pointers to functions, without knowing anything about the objects involved, and without even knowing the name of the operation it invokes. For example:
class write_file : public Action
{
File& f;
public:
int do_it(int)
{
return fwrite( ).suceed( );
}
};
class error_message: public Action
{
response_box db(message.cstr( ),"Continue","Cancel","Retry");
switch (db.getresponse( ))
{
case 0: return 0;
case 1: abort();
case 2: current_operation.redo( );return 1;
}
};

A user of the Action class will be completely isolated from any knowledge of derived classes such as write_file and error_message.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

what is the use of Namespace in c++.

3 Answers  


What is a class definition?

0 Answers  


Explain container class.

0 Answers  


What are protected members in c++?

0 Answers  


What is the use of turbo c++?

0 Answers  






If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?

0 Answers  


write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num

0 Answers   Care,


What are the extraction and insertion operators in c++?

0 Answers  


What do c++ programmers do?

0 Answers  


How does code-bloating occur in c++?

0 Answers  


Why do we need constructors in c++?

0 Answers  


Explain "passing by value", "passing by pointer" and "passing by reference" ?

5 Answers  


Categories