Abstract Classes. Review PA – 3 Design Considerations https://users.cs.jmu.edu/bernstdh /Web/CS239/programs/pa3/draft.php ?harrisnlCS239 https://users.cs.jmu.edu/bernstdh.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

Abstract Classes We often define classes as subclasses of other classes – First, define the superclass – In some cases, a superclass may not have enough.
C++ Classes & Data Abstraction
CS 211 Inheritance AAA.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance Inheritance Reserved word protected Reserved word super
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
9. Inheritance 9.1 Subclasses 9.2 Polymorphism 9.3 Abstract Classes 9.4 Modifiers and Access 9.6 Object-Oriented Design with Use Cases and Scenarios.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Abstract Classes. Lecture Objectives To learn about abstract classes To understand how to inherit abstract classes To understand how to override abstract.
INF 523Q Chapter 7: Inheritance. 2 Inheritance  Another fundamental object-oriented technique is called inheritance, which enhances software design and.
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Abstract Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
UML Class Diagram: class Rectangle
Chapter 10 Classes Continued
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
CC1007NI: Further Programming Week 3 Dhruba Sen Module Leader (Islington College)
Inheritance using Java
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 14.
Inheritance in the Java programming language J. W. Rider.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved2/23 Outline Creating Subclasses Overriding Methods Class Hierarchies.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Coming up: Inheritance
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Polymorphism COMP249. What is an abstract class? a)An abstract class is one without any child classes. b) An abstract class is any parent class with more.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance & Method Overriding BCIS 3680 Enterprise Programming.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
1 More About Derived Classes and Inheritance Chapter 9.
Sections Inheritance and Abstract Classes
Lecture 12 Inheritance.
Inheritance and Polymorphism
03/10/14 Inheritance-2.
Lecture 14 - Abstract Classes
Abstract Classes.
Class Inheritance (Cont.)
Week 6 Object-Oriented Programming (2): Polymorphism
Advanced Programming Behnam Hatami Fall 2017.
Lecture 14- Abstract Classes
Abstract Classes An abstract class is a kind of ghost class. It can pass along methods and variables but it can’t ever be instantiated itself. We can.
Abstract Classes Page
Overriding Methods & Class Hierarchies
Fundaments of Game Design
Chapter 8 Inheritance Part 2.
Lecture 0311 – Polymorphism
Presentation transcript:

Abstract Classes

Review PA – 3 Design Considerations /Web/CS239/programs/pa3/draft.php ?harrisnlCS239 /Web/CS239/programs/pa3/draft.php ?harrisnlCS239

Rules for Abstract Classes An abstract class cannot be instantiated A class that can have instances is said to be concrete An abstract class provides a prototype for other classes to follow

Subclasses of an Abstract Class will inherit the variables and methods of the abstract class will have the same basic characteristics are free to redefine variables and methods and add new ones must override any abstract methods of its parent (unless it itself is abstract).

Abstract Classes generally contain at least one abstract method are any classes containing at least one abstract method can contain non-abstract methods If there is an abstract method, then the class must be declared as abstract, but… If a class is declared as abstract it may or may not have non-abstract or abstract methods.

Abstract Methods have the word abstract in their declaration do not have a body end their declarations with a semi-colon must be overridden in concrete children are generally methods whose bodies will change from one subclass to another

Standard UML Notation +public -private #protected {abstract} (name is italicized) top compartment – class name middle compartment – class attributes  name : type bottom compartment – class methods  name (parameterList types) : return type

Abstract Classes The child of an abstract class must override the abstract methods of the parent, or it too will be considered abstract An abstract method cannot be defined as final (because it must be overridden) or static (because it has no definition yet) The use of abstract classes is a design decision – it helps us establish common elements in a class that is too general to instantiate

Let’s look again at the StaffMember class What will happen if:  We remove the word abstract in the class header?  We change the abstract method to a non-abstract method?  We try to instantiate a StaffMember object?  We decide not to “pay” Volunteers?  We create a new class from the StaffMember object which is an abstract class also?

Another example Shapes - DesigningClasses.pdfDesigningClasses.pdf What should the hierarchy look like? Which classes should be abstract? Which concrete? What services should be required (made abstract)?

Finished product Shape.java TwoDimensionalShape.java ThreeDimensionalShape.java Sphere.java Rectangle.java Rectangle.java