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

Similar documents
Inheritance in Java. Produced by: Eamonn de Leastar Dr. Siobhán Drohan

Chapter 5 Object-Oriented Programming

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

What is Inheritance?

Object Oriented Programming. Java-Lecture 11 Polymorphism

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

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

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

Inheritance and Polymorphism

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

Java Object Oriented Design. CSC207 Fall 2014

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

UML IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

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

Inheritance (Outsource: )

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

Design Patterns. Produced by. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Produced by. Design Patterns. MSc Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Inheritance -- Introduction

CSEN401 Computer Programming Lab. Topics: Object Oriented Features: Abstraction and Polymorphism

CS-202 Introduction to Object Oriented Programming

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

Object oriented programming Concepts

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

Programming II (CS300)

OVERRIDING. 7/11/2015 Budditha Hettige 82

Programming II (CS300)

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

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

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

What are the characteristics of Object Oriented programming language?

CS111: PROGRAMMING LANGUAGE II

Object Oriented Programming: Based on slides from Skrien Chapter 2

PROGRAMMING LANGUAGE 2

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

COMP 110/L Lecture 19. Kyle Dewey

Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces

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

Inheritance CSC 123 Fall 2018 Howard Rosenthal

Polymorphism and Inheritance

Week 5-1: ADT Design

Chapter 6 Introduction to Defining Classes

Object Orientated Programming Details COMP360

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

Object- Oriented Design with UML and Java Part I: Fundamentals

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

CS313D: ADVANCED PROGRAMMING LANGUAGE

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

JAVA MOCK TEST JAVA MOCK TEST II

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

Understanding Inheritance and Interfaces

Practice for Chapter 11

Object Oriented Programming

Object Oriented Paradigm

CSCE3193: Programming Paradigms

Lecture 18 CSE11 Fall 2013 Inheritance

type conversion polymorphism (intro only) Class class

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

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

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

Inheritance, polymorphism, interfaces

Inheritance. Transitivity

Java Overview An introduction to the Java Programming Language

Instance Members and Static Members

The major elements of the object-oriented model

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

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

Chapter 10 Classes Continued. Fundamentals of Java

More Relationships Between Classes

Chapter 5. Inheritance

QUESTIONS FOR AVERAGE BLOOMERS

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

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

INHERITANCE Mrs. K.M. Sanghavi

Chapter 14 Abstract Classes and Interfaces

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Inheritance & Polymorphism. Object-Oriented Programming

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. February 10, 2017

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

C++ Important Questions with Answers

Inheritance, Polymorphism, and Interfaces

BASIC CONCEPT OF OOP

Inheritance and Polymorphism

Example: Count of Points

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

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

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

Concepts 6. OOAD Part II. BlueJ ex 5.1. OO and inheritance. Intro to inheritance. The DoME project is a database for multimedia entertainment.

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

Java How to Program, 8/e

Object Oriented Programming. Michał Bereta

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Object-Oriented Concept

Method Resolution Approaches. Dynamic Dispatch

Transcription:

Object Oriented Concepts Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

Object-Oriented Software Developing object-oriented software is identifying: Objects Characteristics of individual objects Relationships between objects Objects interact by sending messages to each other Interacting objects make an object-oriented system 2

Object-Oriented Terms Objects Classes, instances, fields and methods Encapsulation Polymorphism Inheritance Dynamic binding 3

Objects Every object has: State Behavior State represents data - what an object knows, or what an object contains Behavior represents what an object can do 4

Objects and Loose Coupling object1 state behavior object2 state behavior Changing an object s data does not lead to changes in an object s external behavior object3 state An object s external interface stays the same behavior Promotes loose coupling between objects 5

Object State and Behavior Person object State: age, name, children Behavior: addchild, getage, setage state aperson age name children behavior getage setage addchild 6

Interactions between Objects Object interact by sending messages to each other Objects and interactions between them make up an object-oriented system abroker: apolicyfactory: aperson: createpolicy apolicy new( Joe Smith, 35 years ) apolicy: aperson setowner(aperson) 7

Messages There are two major terms in messaging: Message sender Message receiver Messages may have arguments abroker: aperson: sender getage() receiver message 8

Methods Method is concrete implementation of a message When message is sent to a receiver: Method is found by type of the receiver object and method signature Method code is executed Method represents an object s response to a message 9

Method Signature Method signature is unique identifier of the method It is used to distinguish methods with same name and same number of parameters It consists of: Method name Parameter name Parameter type 10

Object s Public Protocol Public protocol is set of messages that can be sent to an object It does not include messages that an object can send to itself These are private aperson age name children public protocol getage setage addchild 11

Fields Fields represent characteristics of an object Fields are also known as attributes, or instance variables aperson fields age name children getage setage addchild 12

Object-Oriented Principle: Encapsulation Objects hide implementation of the messages behind their public protocols Object s internal implementation is accessed by that object only Encapsulation is also known as implementation hiding abroker: aperson: getname() Joe Smith getage() 35 13

Classes Classes are: Factories for creating objects Template for the same kind of objects that describes their state and behavior Code repository for objects aperson age name children getage setage addchild Classes define objects (by defining their state and behavior) and their type 14

Instances Every object is an instance of some class All instances of same class have the same protocol They have same fields and same methods that are defined by the class Person age name children address getage setage addchild class class Jim Smith 60 Jim Smith John, Tom John Smith 35 John Smith Jimmy, Chloe 15

Object-Oriented Principle: Inheritance Some classes may share commonalities For example HomePolicy, AutoPolicy, LifePolicy classes may all have same state and behavior Instead of repeating commonalities in each class, we can abstract them in a common place These commonalities can be stored in a super class Each subclass inherits state and behavior from its superclass 16

Specialization and Generalization Policy client premium policynumber HomePolicy house getclient setclient AutoPolicy auto LifePolicy specialization gethouse sethouse getauto setauto 17

Why Inheritance? Inheritance represents real-world modeling Some objects are special cases of other objects Inheritance promotes reuse and extensibility Same data and behavior is shared among objects of different types (different class) New data and new behavior that is common for those objects is easier to add 18

Object-Oriented Principle: Polymorphism Polymorphism different objects respond to the same message in different ways For example when asked to talk a dog barks, and a cat meows It is often supported by method overriding Overriding means that subclass may implement the same method as superclass, but with different code tostring() method in the Object class is an example of often overridden method 19

Overriding Example Consider Animal class: Dog and Cat as subclasses All Animal objects should know how to talk Animal acat.talk(); adog.talk(); meows barks talk() Dog talk() Cat talk() 20

Dynamic Binding Dynamic binding represents runtime method binding It is runtime binding of method invoked in the message to the method that implements that message For example::: ananimal.talk(); adog acat talk talk 21

Except where otherwise noted, this content is licensed under a Creative Commons Attribution- NonCommercial 3.0 License. For more information, please see http://creativecommons.org/licenses/by-nc/3.0/