CSC/ECE 517 Fall 2010/ch7 7f PW: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 5: Line 5:
Any time an inherited class overrides a method and is required to call super() first, that is a case of this anti-pattern.  It is not a good idea to require something else being called first.
Any time an inherited class overrides a method and is required to call super() first, that is a case of this anti-pattern.  It is not a good idea to require something else being called first.


{
public class TestCase
public class TestCase
   public void setup() {
   public void setup() {
Line 14: Line 15:
     setupForTCOne();
     setupForTCOne();
   }
   }
}

Revision as of 00:49, 29 November 2010

Call Super Anti-pattern

The Call Super anti-pattern shows up occasionally in object oriented code.


Any time an inherited class overrides a method and is required to call super() first, that is a case of this anti-pattern. It is not a good idea to require something else being called first.

{ public class TestCase

 public void setup() {
   doStuff();
 }

public class TestCaseOne extends TestCase

 public void handle() {
   super.setup();
   setupForTCOne();
 }

}