Chapter 5 Object-Oriented Programming

Similar documents
Practice for Chapter 11

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

CS-202 Introduction to Object Oriented Programming

CS313D: ADVANCED PROGRAMMING LANGUAGE

PROGRAMMING LANGUAGE 2

Programming II (CS300)

Java Object Oriented Design. CSC207 Fall 2014

C++ Important Questions with Answers

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

What is Inheritance?

Inheritance -- Introduction

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Programming II (CS300)

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Inheritance and object compatibility

CH. 2 OBJECT-ORIENTED PROGRAMMING

CS313D: ADVANCED PROGRAMMING LANGUAGE

What are the characteristics of Object Oriented programming language?

Understanding Inheritance and Interfaces

More On inheritance. What you can do in subclass regarding methods:

CGS 2405 Advanced Programming with C++ Course Justification

Object Orientated Analysis and Design. Benjamin Kenwright

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

Software Engineering

Inheritance and Polymorphism

Classwide Programming 1

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Object Oriented Programming. Java-Lecture 11 Polymorphism

Software Development. Modular Design and Algorithm Analysis

CHAPTER 5 GENERAL OOP CONCEPTS

Object Oriented Issues in VDM++

Object-Oriented Design

Type Hierarchy. Lecture 6: OOP, autumn 2003

25. Generic Programming

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Chapter 8: Class and Method Design

New Programming Paradigms

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Data Structures (list, dictionary, tuples, sets, strings)

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

CS1150 Principles of Computer Science Objects and Classes

15CS45 : OBJECT ORIENTED CONCEPTS

Microsoft Visual Basic 2005: Reloaded

Compaq Interview Questions And Answers

CS111: PROGRAMMING LANGUAGE II

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Chapter 2. Building Multitier Programs with Classes The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Lecture 4: Extending Classes. Concept

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

The major elements of the object-oriented model

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

COURSE 2 DESIGN PATTERNS

Polymorphism. return a.doublevalue() + b.doublevalue();

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

HOW AND WHEN TO FLATTEN JAVA CLASSES?

VIRTUAL FUNCTIONS Chapter 10

Introduction to Object-Oriented Programming

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Inheritance (continued) Inheritance

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Chapter 14 Abstract Classes and Interfaces

Object-Oriented Programming

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Inheritance (Part 5) Odds and ends

Object-Oriented Design

Object-Oriented Concepts

Framework Fundamentals

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

Object Oriented Programming: Based on slides from Skrien Chapter 2

OBJECT ORİENTATİON ENCAPSULATİON

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

CS111: PROGRAMMING LANGUAGE II

Object Oriented Concepts. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Introductory Programming Inheritance, sections

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

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

Introduction to Programming Using Java (98-388)

Inheritance (Outsource: )

I Wish I Knew How To. Begin Object Oriented Programming With Xojo. By Eugene Dakin. July 2015 Edition (1.0)

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

ITI Introduction to Computing II

Inheritance and Polymorphism

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Classes Continued. Fundamentals of Java

Transcription:

Chapter 5 Object-Oriented Programming

Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares and/or invokes overridden or overloaded methods and code Develop code that implements is-a and/or has-a relationships

Understanding Object-Oriented Relationships Implementing Polymorphism Conversion of Object Reference Types Using Method Overriding and Overloading

A class and its members are related to each other: the class has data variables in it Classes themselves are related to each other: a class is derived from another class Two kinds of relationships: is-a and has-a, correspond to the two properties of classes: inheritance and data abstraction

The is-a relationship corresponds to inheritance A class is in an is-a relationship with any class up in its hierarchy tree

corresponds to an object-oriented characteristic called encapsulation: the data and the methods are combined into a class

Encapsulation facilitates data abstraction, the relationship between a class and its data members. Tight encapsulation: all data members of the class should be declared private Data abstraction (data hiding): the data is hidden from the user makes the code more reliable, robust, and reusable

refers to minimizing the dependence of an object on other objects can change the implementation of a class without affecting the other classes make the code extensible and easy to maintain demands that a class keep its members private and that the other class access them through getters and setters

access the public member of another class directly

refers to how a class is structured A cohesive class is a class that performs a set of closely related tasks If a class is performing a set of unrelated tasks (a non-cohesive class), you should consider writing multiple classes - reshuffling the tasks

Understanding Object-Oriented Relationships Implementing Polymorphism Conversion of Object Reference Types Using Method Overriding and Overloading

The is-a relationship between a superclass and a subclass: you can substitute an object of the subclass for an object of the superclass

A superclass can have multiple subclasses, giving different meaning to the same thing The capability to convert an object reference from one type to another type

Understanding Object-Oriented Relationships Implementing Polymorphism Conversion of Object Reference Types Using Method Overriding and Overloading

Implicit Conversion of Object Reference Types: Assignment Conversion Method Call Conversion Explicit Conversion of Object Reference Types - object reference casting

The rules are the same as the rules for assignment conversion. The passed-in argument types are converted into the method parameter types when the conversion is valid.

Because object reference conversion may involve reference types and object types: Some of the casting rules relate to the reference type (known at compile time) and therefore can be enforced at compile time. Some of the casting rules relate to the object type (not known at compile time) and therefore can only be enforced at runtime.

Classes: one class must be a subclass of the other. Arrays: the elements of both the arrays must be object reference types. Also, the object reference type of the source array must be convertible to the object reference type of the target array. The casting between an interface and an object that is not final is always allowed

If the target type is a class, then the class of the expression being converted must be either the same as the target type or its subclass. If the target type is an interface, then the class of the expression being converted must implement the target type.

Understanding Object-Oriented Relationships Implementing Polymorphism Conversion of Object Reference Types Using Method Overriding and Overloading

Overriding allows you to modify the behavior of an inherited method to meet the specific needs of a subclass: extensibility Overloading allows you to use the same method name to implement different (but related) functionalities: flexibility

to change the behavior of an inherited method redefine the method by keeping the same signature but rewriting the body The rules for overriding a method: You cannot override a method that has the final modifier. You cannot override a static method to make it non-static. The overriding method and the overridden method must have the same return type

The number of parameters and their types: same You cannot override a method to make it less accessible If the overriding method has a throws clause: The overridden method must have a throws clause Each exception included in the throws clause of the overriding method must be either one of the exceptions in the throws clause of the overridden method or a subclass of it.

The same task is to be performed in slightly different ways under different conditions Multiple methods in a class with identical names No two overloaded methods could have the same parameter types in the same order The return types in overloaded methods may be the same or different