CS111: PROGRAMMING LANGUAGE II

Similar documents
CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

Java How to Program, 8/e

Object Oriented Design

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS111: PROGRAMMING LANGUAGE II

Object-Oriented Programming: Polymorphism

BBM 102 Introduction to Programming II Spring Inheritance

Java Programming Lecture 7

WEEK 13 EXAMPLES: POLYMORPHISM

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

Enhanced Entity- Relationship Models (EER)

CS 209 Sec. 52 Spring, 2006 Lab 6 - B: Inheritance Instructor: J.G. Neal

final Methods and Classes

Introduction to Object-Oriented Programming

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Object Oriented Programming with C++ (24)

Chapter 7. Inheritance

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

Inheritance and Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object-Oriented Programming: Polymorphism Pearson Education, Inc. All rights reserved.

CS112 Lecture: Inheritance and Polymorphism

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Inheritance Introduction. 9.1 Introduction 361

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Object-Oriented Programming: Polymorphism

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Comp 249 Programming Methodology

INHERITANCE. Spring 2019

Chapter 2a Class Relationships

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

OBJECT ORIENTED PROGRAMMING. Abstract Class And Interface

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Java Object Oriented Design. CSC207 Fall 2014

Exam Duration: 2hrs and 30min Software Design

OVERRIDING. 7/11/2015 Budditha Hettige 82

[ L5P1] Object-Oriented Programming: Advanced Concepts

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Object-Oriented Design

COIS Databases

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

5/24/12. Introduction to Polymorphism. Chapter 8. Late Binding. Introduction to Polymorphism. Late Binding. Polymorphism and Abstract Classes

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Lab 10: Inheritance (I)

9/10/2018 Programming Data Structures Inheritance

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

CSE 530A. ER Model. Washington University Fall 2013

Chapter 14 Abstract Classes and Interfaces

Yanbu University College Applied Computer Science (ACS) Introduction to Computer Science (CS 102) Lab Exercise 10

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

C++ Polymorphism. Systems Programming

Big software. code reuse: The practice of writing program code once and using it in many contexts.

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

CPS122 Lecture: Encapsulation, Inheritance, and Polymorphism

Cpt S 122 Data Structures. Inheritance

Inheritance Motivation

10/17/2011. Object Oriented Software Development. Types of interface. Interfaces example

Chapter 4. Enhanced Entity- Relationship Modeling. Enhanced-ER (EER) Model Concepts. Subclasses and Superclasses (1)

Object Oriented Programming. CISC181 Introduction to Computer Science. Dr. McCoy. Lecture 27 December 8, What is a class? Extending a Hierarchy

CPSC 427: Object-Oriented Programming

CS 251 Intermediate Programming Inheritance

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Midterm Exam 5 April 20, 2015

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

JAVA MOCK TEST JAVA MOCK TEST II

Chapter 10 Classes Continued. Fundamentals of Java

More on Inheritance. Interfaces & Abstract Classes

Polymorphism and Interfaces

Chapter 14. Inheritance. Slide 1

Object-Oriented Programming

Chapter 14 Inheritance. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

1.00 Lecture 13. Inheritance

Arrays Classes & Methods, Inheritance

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

CSE 143 Lecture 12 Inheritance

ITI Introduction to Computing II

Interface Class. Lecture 22. Based on Slides of Dr. Norazah Yusof

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

Inheritance -- Introduction

Polymorphism (Deitel chapter 10) (Old versions: chapter 9)

ITI Introduction to Computing II

index.pdf January 21,

Lesson 14: Abstract Classes and Interfaces March 6, Object-Oriented S/W Development with Java CSCI 3381

CSC9T4: Object Modelling, principles of OO design and implementation

Polymorphism and Interfaces. CGS 3416 Spring 2018

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

Programming II (CS300)

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

Transcription:

1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes

Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014

Abstract Classes and Methods CommunityMember is not supposed to be used to create objects abstract superclass Dr. Amal Khalifa, 2014

Abstract Classes and Methods 4 Abstract classes Sometimes it s useful to declare classes for which you never intend to create objects. Cannot be used to instantiate objects abstract classes are incomplete. An abstract class provides a superclass from which other classes can inherit and thus share a common design. Used only as superclasses in inheritance hierarchies, so they are sometimes called abstract superclasses. Not all hierarchies contain abstract classes. Abstract classes sometimes constitute several levels of a hierarchy.

Concrete Classes 5 Classes that can be used to instantiate objects are called concrete classes. must declare the missing pieces in their abstract superclasses provide implementations of every method they declare (some of the implementations can be inherited). provide the specifics that make it reasonable to instantiate objects.

Abstract Classes and Methods 6 Declared with the keyword abstract. normally contains one or more abstract methods. Declared with keyword abstract public abstract void draw(); // abstract method Abstract methods do not provide implementations. A class that contains abstract methods must be an abstract class even if that class contains some concrete (nonabstract) methods. Each concrete subclass of an abstract superclass also must provide concrete implementations of each of the superclass s abstract methods. Constructors and static methods cannot be declared abstract.

7 Programming Pitfalls!! Working with abstract base classes

Case Study: Payroll System 8 A company pays its employees on a weekly basis. The employees are of four types: Salaried employees are paid a fixed weekly salary regardless of the number of hours worked, hourly employees are paid by the hour and receive overtime pay (i.e., 1.5 times their hourly salary rate) for all hours worked in excess of 40 hours, commission employees are paid a percentage of their sales and base-salaried commission employees receive a base salary plus a percentage of their sales. For the current pay period, the company has decided to reward salaried-commission employees by adding 10% to their base salaries. The company wants to write a Java application that performs its payroll calculations polymorphically.

Abstract class names are italicized in the UML. 9 Abstract class names are italicized in the UML.

Abstract Superclass Employee 10 Each Employee has: first name, last name, and a social security number Class Employee provides : tostring method the get and set methods for instance variables. An earnings method An abstract method there is not enough information to determine what amount earnings should return. applies to all employees, each earnings calculation depends on the employee s class. Each subclass overrides earnings with an appropriate implementation.

11 Concrete Subclasses

The Employee class 12 Abstract class abstract keyword

13

14

15 Concrete Subclasses

SalariedEmployee class 16 One concrete class

17

HourlyEmployee class 18 hourly employees are paid by the hour and receive overtime pay (i.e., 1.5 times their hourly salary rate) for all hours worked in excess of 40 hours,

19

20

CommissionEmployee class 21 commission employees are paid a percentage of their sales

22

CommissionEmployee class 23 The last one!!

24

25 That s all for today.. Working on Chapter 10..