Use Polymorphism

Use Polymorphism: Programs, especially those converted from non-OOP languages like C, sometimes use state where they should use inheritance. For example,

1225_polymorphism1.jpg

The variable type is used to explicitly store the type of an instance of class A or B. It is initialized in the constructors of both classes and is used in the A::foo() method to determine the exact type of the object so that the appropriate operations are carried out. Besides being error prone (type initialization, branch completeness) and breaking fundamental object-oriented abstraction rules (base classes should not have to know about their concrete derived classes), this produces more code (the branches) and more data (type fields) that have to be handled by the model checker. You can use the inheritance mechanism in C++ to do this more elegantly, as shown below:

856_polymorphism2.jpg

   Related Questions in Programming Languages

  • Q : State Precedence rules Precedence rules

    Precedence rules: The rules which determine the order of computation of an expression comprising more than one operator. The operators of higher precedence are computed before those of lower precedence. For example, in the expression x+y*z, the multip

  • Q : What is Actual argument Actual argument

    Actual argument: The value of an argument enacted to a method from exterior to the method. Whenever a method is called, the real argument values are copied into analogous formal arguments. The kinds of the actual arguments should be compatible with th

  • Q : Describe Method result Method result :

    Method result: The value returned from a method through a return statement. The kind of expression in the return statement should match the return type declared in method header.

  • Q : Define the term Boot Boot: Whenever a

    Boot: Whenever a computer is switched on it is said to be `boot up'. This word comes from the phrase, “Pulling yourself up by your bootstraps”. Before a computer is ready to be utilized, it should load the programs which it requires from i

  • Q : Define Loop variable Loop variable : A

    Loop variable: A variable employed to control the operation of a loop, like a for loop. Usually, a loop variable will be provided an initial value and it is then incremented after each and every iteration till it passes or reaches a terminating value.

  • Q : Explain Static variable Static variable

    Static variable: It is a static variable defined within a class body. Such a variable fits in to the class as a whole, and is, thus, shared by all objects of the class. The class variable may be employed to define the default value of an instance vari

  • Q : What is Bookmark Bookmark : It is

    Bookmark: It is employed by a Web browser to memorize details of a Uniform Resource Locator (URL).

  • Q : State Space Reduction in Java PathFinder

    State Space Reduction: JPF is a so-called explicit-state model checker, as it enumerates all visited states, and therefore suffers from the state explosion problem inherent in analyzing large programs. It also contains garbage collection, because a ty

  • Q : Function overloading in C plus Function

    Function overloading in C++: The function name containing numerous definitions which are differentiable by the number or kinds of their arguments is termed as function overloading.

  • Q : State the term dispatcher State the

    State the term dispatcher.

©TutorsGlobe All rights reserved 2022-2023.