Category: 

What Is an Abstract Method?

Article Details
  • Written By: Jean Marie Asta
  • Edited By: Jessica Seminara
  • Last Modified Date: 20 August 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
In late 19th-century London, mail was delivered to residential addresses up to twelve times each day.   more...

September 28 ,  1924 :  Two US military planes complete the first flights around the world.  more...

In object oriented programming, subroutines called “methods” are used to perform functions in a program. These methods consist of programming statements that perform an action, set up input parameters to customize actions, and can return or output a value of some kind of object or class. Methods are the actions performed in a program from a certain class or within an object, and are used to access and manipulate data stored within an object. There are many different methods and each has a particular use. A specific type that is performed from an abstract super class and inherited by subclasses is known as an abstract method.

Generally, the abstract method performs little or no implementation within its abstract super class. Codes contained within this kind of method are considered dummy codes and are not implemented themselves. This does not mean the specific abstract method in a particular abstract class does not get used. Rather, the abstract method acts as a model or placeholder for subclasses to finish the implementation of the method.

Ad

Super classes may contain multiple subclasses, and all subclasses of a super class have certain similar states and behaviors. Abstract classes, therefore, are a type of virtual class that exhibits virtual inheritance. This means that any subclass derived from a super class inherits the restrictions of the super class from which it is derived. Therefore, methods in subclasses are derived from abstract methods of super classes. When programming and using abstract methods, the programmer must declare the class abstract rather than virtual.

For example, a super class of “Graphic Objects” contains the subclasses “Circle,” “Square,” etc. As such, all Circles and Squares have the same states — orientation, position, fill color, line color — and behaviors — moveTo, resize, rotate, draw — as “Graphic Objects.” All subclasses in this super class have the same qualities, but they are implemented in different ways. The abstract method of the super class provides the groundwork without implementation, and the subclasses perform the actual implementation using the same methods. Even though each subclass uses the same method as the abstract class, they uniquely define the way in which the method will be carried out.

Using an abstract method allows for generalization at the top level, or super class, and specification at the lower levels, or subclasses. This hierarchy minimizes the amount of method programming to each specific subclass. Using these methods also allows for idempotency of subclasses, meaning that if a method is implemented over and over, the result is the same every time.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}