Lecture 2 Object-oriented programming. Definitions of OOP OOP is a programming paradigm, which utilizes encapsulation, inheritance and polymorphism. (From.

Slides:



Advertisements
Similar presentations
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
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
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSSE501 Object-Oriented Development
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
OOP Languages: Java vs C++
Abstraction, Inheritance, and Polymorphism in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Elements of OO Abstraction Encapsulation Modularity Hierarchy: Inheritance & Aggregation 4 major/essential elements3 minor/helpful elements Typing Concurrency.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Object-Oriented Programming Chapter Chapter
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
ISBN Object-Oriented Programming Chapter Chapter
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
CSC 205 Java Programming II Abstract Data Type. Abstraction The meaning of abstraction Abstraction arises from a recognition of similarities between certain.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Introduction to Object Oriented Programming Lecture-3.
ISBN Chapter 12 Support for Object-Oriented Programming.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Modern Programming Tools And Techniques-I
The Movement To Objects
Inheritance ITI1121 Nour El Kadri.
Abstraction, Interface, Inheritance, Polymorphism, Override / Overload
Topic: Classes and Objects TALENTSPRINT | © Copyright 2012
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Week 6 Object-Oriented Programming (2): Polymorphism
Lecture 11 Abstract Data Type
Object Oriented Design & Analysis
Lecture 10 Concepts of Programming Languages
Presentation transcript:

Lecture 2 Object-oriented programming

Definitions of OOP OOP is a programming paradigm, which utilizes encapsulation, inheritance and polymorphism. (From standard programming languages textbook)

Definitions of OOP OOP is a method of implementation in which programs are organized as cooperative collections of objects, each of which, represents an instance of some class, and whose classes are all members of a hierarchy of classes united via inheritance relationship. (Grady Booch, Object-oriented analysis and design)

Definitions of OOP OOP is a way of modeling computation which attempts to mimic the way we see the world around us.

Grady Booch on Abstraction is one of the fundamental ways that we as humans cope with complexity arises from recognition of similarities between certain objects, situations or processes in the real world facilitates principle of least astonishment

Grady Booch on Abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provides crisply defined conceptual boundaries, relative to the perspective of the viewer captures the entire behavior of some object, no more, no less, and offers no surprises or side effects that go beyond the scope of the abstraction.

Encapsulation public class Car { private String serialNumer; private String make; private double tankVolume; private double speed; }

Encapsulation public class Car { // Public section public String getSerialNumber() { return serialNumber; } public String getMake() { return make; } public double getTankVolume() { return tankVolume; } public double getSpeed() { return speed; } // Private section private String serialNumer; private String make; private double tankVolume; private double speed; }

Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate contractual interface of an abstraction and its implementation. (from Grady Booch’s Object-oriented analysis and design)

Inheritance Is-a relationship (is kind of) Dog is a Mammal Professor is (usually) Human Running is an Exercise

Inheritance is about organizing abstractions into hierarchies.

Inheritance At the top of inheritance hierarchy is a base class. Typically, a base class would be abstract, meaning it would correspond to a concept, a not to a physical entity. This class would explicitly prohibit you to create instances of itself. public abstract class Engine {} Implies that Engine myEngine = new Engine(); would not compile.

Inheritance Derived class inherits interface and implementation from the base class.

Inheritance for extension Is when derived class adds functionality to the base class public class Point {public class ColorPoint extends Point { public int getX(); public Color getColor(); public int getY();} } Another example public class Derived extends Base { public void build() { super.build(); // do some more }

Inheritance for reuse Is when derived class doesn’t add functionality to most methods of the base class Sometimes, the designer of a base class may intentionally specify a method as final. public class Base { public final void getName() { return sName; } public class Derived extends Base { public void getName() { // WOULD NOT COMPILE }

An interface is an expression of pure design, whereas class is a mix of design and implementation. From Arnold & Gosling 'Java programming language'

public interface IDatabase { public String getName(); public ITable getTable( String name ); public Iterator tables(); public Iterator tableNames(); }

public class RelationalDatabase implements IDatabase public class FileDatabase implements IDatabase

public void setDatabase( IDatabase db ) { if ( db instanceof RelationalDatabase ) { processRelationalDatabase( (RelationalDatabase)db ); } else if ( db instanceof FilelDatabase ) { processFilelDatabase( (FilelDatabase)db ); }... } DON’T DO THIS….

class GraphicalTextEditor : public TextEditor, Component;

public class TextEditor {} public class Component {} public class GraphicalTextEditor extends TextEditor { public Component getComponent() { return c; } // Inner class GraphicalTextEditorComponent which takes care // of the graphical aspect of this text editor. private class GraphicalTextEditorComponent extends Component { } private Component c = new GraphicalTextEditorComponent(); }

Aggregation Objects of a class have a reference (member field) one or more objects of another class public class Car { … private Engine engine; }

Object of another class is passed as an argument into a method. public class PnLCalculator { public static double computePnL( ITrade[] tradeList ) { } private PnLCalculator() {} } Uses

Interface can extend another interface public interface List extends Collection

public interface IDynamicProperties { public void addProperty( String name, Object value ); public Object getProperty( String name ); public Object removeProperty( String name ); public Iterator properties(); public Iterator propertyNames(); } public interface Clonable { public Object clone(); }

public class Entity implements IDynamicProperties, Clonable {.. // Implementation of Dynamic properties interface public void addProperty( String name, Object value ) { htProperties.put( name, value ); }... // implementation of Clonable interface { public Object clone() { Entity newEntity = new Entity(); // copy all fields return newEntity; }

public class TreeNode { public Object deepCopy() { TreeNode newNode = new TreeNode(); // copy all the fields // copy children for ( Iterator i = getChildren();i.hasNext(); ) { TreeNode child = (TreeNode)i.next(); newNode.addChild( child.deepCopy() ); }

public interface Iterator { public boolean hasNext(); public Object next(); public void remove(); }

for ( Iterator i = getChildren(); i.hasNext(); ) { TreeNode child = (TreeNode)i.next(); newNode.addChild( child.deepCopy() ); }

public abstract class Entity public String getName() { return name; } public void setName( String name ) { this.name = name; } public abstract Object getUniqueId(); private String name; }

IFoo AbstractFoo DefaultFoo ABitDifferentFoo VeryDifferentFoo

Please read Chapters 2, 4, 5,6, 10, 11 in Java programming language by Arnold & Gosling Chapters 1 and 2 in Design Patterns by Gamma, etc.