March 31, 2000CS102-01Lecture 1.3 Introduction to Object-Oriented Programming CS 102-02 Lecture 1-3.

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

Inheritance Inheritance Reserved word protected Reserved word super
Object-Oriented PHP (1)
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
April 29, 1998CS102-02Lecture 5-2 Object-Oriented Programming: Polymorphism & Abstraction CS Lecture 5-2 The Wonderful World of Objects.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.
C++ fundamentals.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
TCU CoSc Introduction to Programming (with Java) Getting to Know Java.
Abstraction, Inheritance, and Polymorphism in Java.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Programming Languages and Paradigms Object-Oriented Programming.
Module 7: Essentials of Object-Oriented Programming.
Eclipse – making OOP Easy
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Java Classes Using Java Classes Introduction to UML.
1. 2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage.
Object-Oriented Programming (OOP) CSC-2071 (3+1=4 Credits) Lecture No. 1 MBY.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
April 3, 1998CS102-02Lecture 1-3 Introduction to Object-Oriented Programming CS Lecture 1-3.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Inheritance A Review of Objects, Classes, and Subclasses.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Abstraction ADTs, Information Hiding and Encapsulation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
CSCE 240 – Intro to Software Engineering Lecture 3.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Classes and OOP.
Object-Oriented Analysis and Design
Chapter 11 Object-Oriented Design
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
CSC 205 Programming II Lecture 2 Subclassing.
IFS410: Advanced Analysis and Design
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented PHP (1)
The Object Paradigm Classes – Templates for creating objects
Presentation transcript:

March 31, 2000CS102-01Lecture 1.3 Introduction to Object-Oriented Programming CS Lecture 1-3

March 31, 2000CS102-01Lecture 1.3 Before You Write a Program... Decide on data –What input does your program need? –What data will it manipulate? –What information will it produce? Actions –Things your program does

March 31, 2000CS102-01Lecture 1.3 Types of Data Related data –Automobiles –Whole numbers –Fractions –Sentences

March 31, 2000CS102-01Lecture 1.3 How Do Actions and Data Relate? Actions can act on data –Square root procedures act on numbers –Problem: Need different actions for different data Actions and data can coexist –Objects combine both data and actions into one package

March 31, 2000CS102-01Lecture 1.3 Driving a Car When you step on the gas in a car, do you think: –“I’m calling the accelerate procedure and passing it a pink Chevy Malibu and a pedal position.” –Or, “Chevy Malibus ‘know’ how to accelerate already and I’m just asking the car to do its thing.”?

March 31, 2000CS102-01Lecture 1.3 The World is Full of Objects I Some objects in the world, and what they can do: ObjectActions Chevy MalibusStop, go, turn MicroscopesFocus, insert slide, remove slide HotelsMake up rooms, check in guests

March 31, 2000CS102-01Lecture 1.3 The World is Full of Objects II Some objects in the world, and what they know: ObjectData Chevy MalibusGas level, coolant level, top speed MicroscopesSlide light on? HotelsNumber of conference rooms

March 31, 2000CS102-01Lecture 1.3 Object Relationships Objects can contain other objects –Composition –“Has a” (or “hath” if you’re an English author) relationship Objects are more specific versions of other objects –Inheritance –“Is a” relationship

March 31, 2000CS102-01Lecture 1.3 Inheritance

March 31, 2000CS102-01Lecture 1.3 Same Car, Different View

March 31, 2000CS102-01Lecture 1.3 The Welcome Applet // A first program in Java // import Applet class import java.applet.Applet; // import Graphics class import java.awt.Graphics; public class Welcome extends Applet { public void paint( Graphics g ) { g.drawString( "Welcome to Java Programming!", 25, 25 ); } A “Welcome” is a kind of “Applet”

March 31, 2000CS102-01Lecture 1.3 Reuse, Reuse, Reuse O-O concepts make it easy to reuse –Inheritance: Someone else creates the general, and you add specifics –Composition: Put the puzzle pieces together “Writing good software is hard, so avoid it whenever possible.” - Kurt Fenstermacher

March 31, 2000CS102-01Lecture 1.3 Building an Airport What actions do airports know how to perform? What attributes do airports have? Are airports a kind of something? What kinds of airports are there? Do airports have logical subparts?

March 31, 2000CS102-01Lecture 1.3 “Just Like Summer Vacation, -- No Class” A class is a specification of : –Structure (the data, a.k.a. instance variables) –Actions (methods) –Inheritance (parents, or derived structure and actions) for objects.

March 31, 2000CS102-01Lecture 1.3 Examples of Classes Related groups of things constitute a class Share the same structure, actions (behavior) and similarly derived –Aardvarks –Airports –Applets

March 31, 2000CS102-01Lecture 1.3 Classes in Java If you’ll need a group of related objects, create a class: class Point { int x, y; } Define a class with: class classname { Class definition (some data and/or some actions) }

March 31, 2000CS102-01Lecture 1.3 Classes Have Data Airport class –Gates –Runways –Airlines Class data goes inside the class definition, usually at the very beginning: public class Time1 { private int hour; // private int minute; // private int second; //

March 31, 2000CS102-01Lecture 1.3 Classes Know Actions Classes aren’t just data, but actions too –At the airport Delivering baggage Preparing for plane’s arrival –Class actions are called methods

March 31, 2000CS102-01Lecture 1.3 Types Type is similar to class: a collection of data and actions Usually, we’ll consider type and class to be the same thing –In Java there are interfaces and classes

March 31, 2000CS102-01Lecture 1.3 Abstract Data Types ADTs (from HTP 6.16) are implemented in Java with classes –An airport class represents the abstract notion of a class –The Platonic “form”

March 31, 2000CS102-01Lecture 1.3 Objects are Instances Classes are the overarching concepts –Concept “airport” is an abstract notion Objects are instances of those classes –O’Hare, LAX and Heathrow are concrete instances of airports Airport : O’Hare :: Class : Object

March 31, 2000CS102-01Lecture 1.3 Creating an Object Use new : Airport peotone = new Airport(“Peotone, IL”); Give the variable a name What type of variable is it? Some airport specification You want a new what?

March 31, 2000CS102-01Lecture 1.3 Java Object Magic Creating objects is easy in Java –Forget about memory ‘cuz Java’s simple Want another airport, just call new again!

March 31, 2000CS102-01Lecture 1.3 Creating Instances from Classes Real-world –Spend money to hire construction crews –Lay asphalt –Build roads In Java, build airports with constructors –Special methods defined in a class which set up new objects –Same name as class

March 31, 2000CS102-01Lecture 1.3 Building Time public class Time1 { private int hour; // private int minute; // private int second; // // Time1 constructor initializes each // instance variable to zero. Ensures // that each Time1 object starts in a // consistent state. public Time1() { setTime( 0, 0, 0 ); } Anybody can create a new Time1 object Constructors have the same name as the class

March 31, 2000CS102-01Lecture 1.3 Hiding (a.k.a. Encapsulating) Data Airport operations –Do you know: Outer marker? NDB? ATIS Frequency for O’Hare? Use the airport because you only need to know a little –Parking lot, ticket counter, baggage claim,...

March 31, 2000CS102-01Lecture 1.3 Why Hide Data? Can’t break it –What if you could change the tower frequency? –Double-check data Easier for you –What if you couldn’t get on a plane without knowing how to operate a jetway? Inner workings can change –Change the guts of the airport, but don’t change the ticket counter, baggage claim,...

March 31, 2000CS102-01Lecture 1.3 Hiding Data in Java public class Time1 { private int hour; // private int minute; // private int second; // // Time1 constructor initializes each instance variable // to zero. Ensures that each Time1 object starts in a // consistent state. public Time1() { setTime( 0, 0, 0 ); } Nobody can mess with hour, minute or second Nobody can set hour = “ABC” or minute = “456.45”

March 31, 2000CS102-01Lecture 1.3 Hiding Time public class Time1 { private int hour; // private int minute; // private int second; // // Time1 constructor initializes each // instance variable to zero. Ensures // that each Time1 object starts in a // consistent state. public Time1() { setTime( 0, 0, 0 ); } Anybody can create a new Time1 object One of our reasons for data hiding

March 31, 2000CS102-01Lecture 1.3 Object-Oriented Means… I Objects: Combining data and actions under one roof Hierarchies: An ranking of abstractions –Inheritance: The “is a” hierarchy –Composition: The “part of” hierarchy Abstraction: What distinguishes an object from other kinds objects, given a particular perspective

March 31, 2000CS102-01Lecture 1.3 Object Oriented Means… II Hiding data: Only the essentials are visible to the outside world Modularity: Group related abstractions together