COMP 303 Lecture Notes - Lecture 14: Null Pointer, Multiple Inheritance

62 views6 pages

Document Summary

14 template method pattern & protected interfaces: textbook chapter 6. 4 and 6. 5. Problem: i have steps to payment, and i want to do these steps in speci c ways. Solution: use the template method pattern to force the steps in a speci c order. Non-abstract method call the abstract methods to force a sequence of steps abstract methods. Subclasses add code to abstract methods to implement real actions abstract class paymentobject { bool makepayment(double amount) { Ans = pay(ptr, amount); return ans; abstract void paymentinfo(); abstract void connect(info info); abstract void pay(account ptr, double amount); // implement body of of abstract methods in child class creditcardpayment extends paymentobject { void paymentinfo() { } void connect(info info) { } void pay(account ptr, double amount) { } Note: deal with a set of subclass methods whose implementations are almost identical. Clericalsta member x = new clericalsta member( ); abstract class clericalsta member { }

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents