Object-Oriented Programming

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Classes & Objects Computer Science I Last updated 9/30/10.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Programming Languages and Paradigms Object-Oriented Programming.
Introduction to Object-oriented programming and software development Lecture 1.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Chapter 8 More Object Concepts
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
By : Robert Apeldorn. What is OOP?  Object-oriented programming is a programming paradigm that uses “objects” to design applications and computer programs.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
CSCE , SPRING 2016 INSTRUCTOR: DR. NANCY M. AMATO 1.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Data Structures and Algorithms in JAVA Chapter 2.
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Data Abstraction: The Walls
Object-Oriented Design
Object Oriented Programming
The Movement To Objects
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Object-Oriented Programming
Ch. 2 Object-Oriented Programming
Inheritance and Polymorphism
Java Primer 1: Types, Classes and Operators
Chapter 11 Object-Oriented Design
About the Presentations
Lecture 2 of Computer Science II
Week 4 Object-Oriented Programming (1): Inheritance
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Concepts
Object Oriented Analysis and Design
Object-Oriented Programming
MSIS 670 Object-Oriented Software Engineering
Advanced Programming Behnam Hatami Fall 2017.
Chapter 20 Object-Oriented Analysis and Design
Java – Inheritance.
Java Programming, Second Edition
Inheritance and Polymorphism
CS2013 Lecture 7 John Hurley Cal State LA.
Oriented Design and Abstract Data Type
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
Presentation transcript:

Object-Oriented Programming 1/27/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Object-Oriented Programming © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 1 1

Terminology Each object created in a program is an instance of a class. Each class presents to the outside world a concise and consistent view of the objects that are instances of this class, without going into too much unnecessary detail or giving others access to the inner workings of the objects. The class definition typically specifies instance variables, also known as data members, that the object contains, as well as the methods, also known as member functions, that the object can execute. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 2

Goals Robustness Adaptability Reusability We want software to be capable of handling unexpected inputs that are not explicitly defined for its application. Adaptability Software needs to be able to evolve over time in response to changing conditions in its environment. Reusability The same code should be usable as a component of different systems in various applications. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 3

Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures gives rise to abstract data types (ADTs). An ADT is a model of a data structure that specifies the type of data stored, the operations supported on them, and the types of parameters of the operations. An ADT specifies what each operation does, but not how it does it. The collective set of behaviors supported by an ADT is its public interface. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 4

Object-Oriented Design Principles Modularity Abstraction Encapsulation © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 5

Design Patterns Algorithmic patterns: Recursion Amortization Divide-and-conquer Prune-and-search Brute force Dynamic programming The greedy method Software design patterns: Iterator Adapter Position Composition Template method Locator Factory method © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 6

Object-Oriented Software Design Responsibilities: Divide the work into different actors, each with a different responsibility. Independence: Define the work for each class to be as independent from other classes as possible. Behaviors: Define the behaviors for each class carefully and precisely, so that the consequences of each action performed by a class will be well understood by other classes that interact with it. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 7

Class Definitions A class serves as the primary means for abstraction in object-oriented programming. In Java, every variable is either a base type or is a reference to an instance of some class. A class provides a set of behaviors in the form of member functions (also known as methods), with implementations that belong to all its instances. A class also serves as a blueprint for its instances, effectively determining the way that state information for each instance is represented in the form of attributes (also known as fields, instance variables, or data members). © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 8

Constructors A user can create an instance of a class by using the new operator with a method that has the same name as the class. Such a method, known as a constructor, has as its responsibility is to establish the state of a newly object with appropriate initial values for its instance variables. 9 © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming

Inheritance A mechanism for a modular and hierarchical organization is inheritance. This allows a new class to be defined based upon an existing class as the starting point. The existing class is typically described as the base class, parent class, or superclass, while the newly defined class is known as the subclass or child class. There are two ways in which a subclass can differentiate itself from its superclass: A subclass may specialize an existing behavior by providing a new implementation that overrides an existing method. A subclass may also extend its superclass by providing brand new methods. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 10

Inheritance and Constructors Constructors are never inherited in Java; hence, every class must define a constructor for itself. All of its fields must be properly initialized, including any inherited fields. The first operation within the body of a constructor must be to invoke a constructor of the superclass, which initializes the fields defined in the superclass. A constructor of the superclass is invoked explicitly by using the keyword super with appropriate parameters. If a constructor for a subclass does not make an explicit call to super or this as its first command, then an implicit call to super( ), the zero-parameter version of the superclass constructor, will be made. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 11

An Extended Example A numeric progression is a sequence of numbers, where each number depends on one or more of the previous numbers. An arithmetic progression determines the next number by adding a fixed constant to the previous value. A geometric progression determines the next number by multiplying the previous value by a fixed constant. A Fibonacci progression uses the formula Ni+1=Ni+Ni-1 © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 12

The Progression Base Class © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 13

The Progression Base Class, 2 © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 14

ArithmeticProgression Subclass © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 15

GeometricProgression Subclass © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 16

FibonacciProgression Subclass © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 17