Object-Oriented Programming

Similar documents
Object-Oriented Programming. Objects. Objects. Objects

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Object-Oriented Programming Concepts

Collections. Collections Collection types Collection wrappers Composite classes revisited Collection classes Hashtables Enumerations

Collections. Collections. Collections - Arrays. Collections - Arrays

Object Oriented Programming

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CO Java SE 8: Fundamentals

Introduction to OOP. Procedural Programming sequence of statements to solve a problem.

Programmazione. Prof. Marco Bertini

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

Object oriented programming Concepts

Objective-C: An Introduction (pt 1) Tennessee Valley Apple Developers Saturday CodeJam July 24, 2010 August 7, 2010

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Lecture 6 Introduction to Objects and Classes

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

OBJECT-ORIENTED MODELING AND DESIGN. Introduction

Chapter 2: Java OOP I

CSI 32. Lecture Object-Oriented Paradigm. UML (Unified Modeling Language)

Understanding the Object Paradigm

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

Software and Programming 1

LECTURE1: PRINCIPLES OF DATABASES

Object Oriented Programming. Michał Bereta

Unit - IV CHAPTER - 13 INTRODUCTION TO OOP WITH C++ Part 1 Choose the best answer

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Course 3 7 March

UML Primer. -Elango Sundaram

Arrays Classes & Methods, Inheritance

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Introduction. Object Orientated Analysis and Design. Benjamin Kenwright

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

Object-Oriented Introduction

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Object Oriented Programming

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

10. Java Classes. Classes - Technical. Example: Earthquake catalog. Classes - Conceptual

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

Collections of Objects. Object Oriented Programming Camilo López

Chapter 2. Database Design. Database Systems p. 25/540

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Instance Members and Static Members

UNIT-I Introduction of Object Oriented Modeling

13. Java Classes. Educational Objectives. Classes - Technical. Definition: Classes

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

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

CS200: Advanced OO in Java

Abstract Classes Interfaces CSCI 201 Principles of Software Development

Abstract Classes Interfaces CSCI 201 Principles of Software Development

JAVA: A Primer. By: Amrita Rajagopal

Chapter 4 Defining Classes I

Introduction to Object-Oriented Programming

Polymorphism. Polymorphism Abstract Classes Interfaces

Enhanced Entity- Relationship Models (EER)

Module Outline. What is Object-Oriented? Some Possible Definitions. Why Object-oriented? Fundamentals of Object Orientation

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

COWLEY COLLEGE & Area Vocational Technical School

JAVA GUI PROGRAMMING REVISION TOUR III

Object Orientated Analysis and Design. Benjamin Kenwright

CS 1331 Fall 2016 Exam 2

Spring % of course grade

CS 246: Software Abstraction and Specification. Lecture 8. Object Composition

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Programming II (CS300)

Implements vs. Extends When Defining a Class

Database Management Systems MIT Introduction By S. Sabraz Nawaz

Java Learning Object Ontology

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

Introduction to Object- Oriented Programming

Chapter 5: Classes and Objects in Depth. Information Hiding

Faculty Portal. Logging In:

Chapter3: Introduction to Classes and Objects

Example: Fibonacci Numbers

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Week 5-1: ADT Design

Entity Relationship Data Model. Slides by: Shree Jaswal

Lecture 18 Tao Wang 1

OO Requirements to OO design. Csaba Veres Alan M. Davis (1995), Colorado

What are the characteristics of Object Oriented programming language?

Classes, Objects, and OOP in Java. June 16, 2017

Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction

Entity-Relationship Models: Good Design and Constraints

Abstraction. Abstraction

DOWNLOAD OR READ : OBJECT ORIENTED PROGRAMMING IN C BY ROBERT LAFORE 3RD EDITION PDF EBOOK EPUB MOBI

Event Handling Java 7

CSCU9T4: Managing Information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Logging into and using MyBC

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

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Chapter 11 Object and Object- Relational Databases

Score. 1 (10) 2 (10) 3 (8) 4 (13) 5 (9) Total (50)

MechEng SE3 Lecture 7 Domain Modelling

Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412

Online Registration Instructions

Programming in C# Inheritance and Polymorphism

Java Programming. U Hou Lok. Java Aug., Department of Computer Science and Information Engineering, National Taiwan University

Transcription:

References: Beginning Java Objects by Jacquie Barker; Designing Object-Oriented Software by Rebecca Wirfs- Brock;Object-oriented Analysis & Design by Grady Booch; Sara Stoecklin 9/11/2003 1 Object Oriented Programming defined Object orientation: Objects and Classes Defining classes in Java Composition: Objects as Attributes 9/11/2003 2 Object-Oriented Programming Object-oriented programming 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 relationships. --Grady Booch Main points in this definition: Objects (not algorithms) are fundamental logical building blocks each object is an instance of some class classes are related via inheritance( is-a relationship) Programming without inheritance is doing object-based programming 9/11/2003 3 1

Objects Objects are based on a blueprint, prototype, model Example blueprints : 9/11/2003 4 Objects Object: something material that may be perceived by the senses; something mental or physical toward which thought, feeling, or action is directed. (Merriam Webster dictionary) Physical objects that may comprise a student registration system: professors students classrooms 9/11/2003 5 Objects Conceptual objects that may be found in the system: courses departments degrees Software object:: a software construct that bundles together data (state) and functions (behavior) which, taken together, represent an abstraction of a real-world (physical or conceptual) object. -- Barker 9/11/2003 6 2

Objects Objects retain certain information and know how to perform certain operations. The bundling of state and behavior of an object is known as encapsulation. An object has a public interface and a private representation. This is known as information hiding. You can change the internal representation of an object or implement a new algorithm for a specific operation without changing the object s abstract, public interface. 9/11/2003 7 Classes A class is an abstraction describing the common features of all members in a group of similar objects. -- Barker Classes are models of real-world entities. Objects are examples (instances) of these classes. Instance Model You define the model (house plan) one time and use that model to create many instances (houses). 9/11/2003 8 Object-Orientation An object is an instance of a class Class Instance (object) Student John Douglas ID #23434 The Student is the class and uniquely identified John Douglas ID#23434 is an object or instance of that class. 9/11/2003 9 3

Object-Orientation An object is an instance of a class Class Instance (object) Student John Douglas ID #23434 Television Zenith serial #3568755 A Television is the class and uniquely identified Zenith with a serial # 3568755 is an instance of that class. 9/11/2003 10 Object-Orientation An object has state - characteristics (attributes) behavior - what an object does Example Object State(s) Behaviors Zenith Channel, Size Turn off, #4353 Increase Volume A TV object Zenith #4353 has states of the size of the TV and the Channel displayed on the TV. It also has behaviors such as turn off the TV or increase the volume on Zenith #4353 TV. 9/11/2003 11 Objects Data/State/Attributes associated with a student student name student ID and/or SSN student birth date student address student major, if declared student GPA student s advisor student s current course load student s transcript 9/11/2003 12 4

Objects Data/State/Attributes associated with a course course number course name course s prerequisites course credit hours course instructors Attributes are data elements used to describe an object Collectively, attributes define object state 9/11/2003 13 Objects Behavior/Operations/Methods associated with a student object may include: enroll in a course drop a course choose a major select a faculty advisor reveal GPA when asked reveal whether a particular course has been taken and all information about the course (when taken, who the instructor was, what grade earned) 9/11/2003 14 Objects Behavior/Operations/Methods associated with a course: permit student to register for determine if student already in the course reveal how many students registered thus far or how many seats remain reveal course prerequisites reveal course credit hours reveal who is teaching the course 9/11/2003 15 5

Objects Object behavior includes accessing its own attributes and modifying/ maintaining its attributes Operations (methods) are also thought of as services that an object performs for its clients. 9/11/2003 16 Defining New Classes in Java A Java class is a blueprint for an object. Class blueprint void { Console.println(Id); }// end The class definition Memory Instance For Class Student 9/11/2003 17 id : gpa : Defining New Classes in Java Student mystudent; mystudent mystudent = new Student(); mystudent id : gpa : Creates mystudent of TYPE Student Creates the memory to store the values in the variables for mystudent 9/11/2003 18 6

Defining New Classes in Java public class StudentTest { public static void main(string args[ ] ) { Student S1; S1 = new Student( ); S1.id = 1234; S1.gpa = 3.5; S1.printId( ); }// end main Test id : gpa : S1 To use the class or data type, you must first instantiate an object using new. When the new statement is executed it creates a new memory instance called S1 from the blueprint defined in the Student class. 9/11/2003 19 Defining New Classes in Java public class StudentTest { public static void main(string args[ ] ) { Student S1; S1 = new Student( ); S1.id = 1234; S1.gpa = 3.5; S1.printId( ); }// end main Test Defines a variable named S1 of type Student within the class Student Test Defines the memory for S1 id : gpa : 9/11/2003 20. S1 Defining New Classes in Java public class StudentTest { public static void main(string args[ ] ) { Student S1; S1 = new Student( ); S1.id = 1234; S1.gpa = 3.5; S1.printId( ); }// end main Test Assigns the value of 3.5 to the Assigns instance the variable value 1234 gpa to in id the in the memory referenced by by S1. S1. id : 1234 gpa : 3.5 9/11/2003 21 S1. 7

Defining New Classes in Java public class StudentTest { public static void main(string args[ ] ) { Student S1; S1 = new Student( ); S1.id = 1234; S1.gpa = 3.5; S1.printId( ); }// end main Test Assigns The the value 1234 to id in method the memory printid is called referenced in the instance by S1. S1... id : 1234 gpa : 3.5 9/11/2003 22 S1 Defining New Classes in Java public class StudentTest { public static void main(string args[ ] ) { Student S1; S1 = new Student( ); S1.id = 1234; S1.gpa = 3.5; S1.printId( ); }// end main Test Thus the variable referenced as S1.id has the value 1234 in its memory location. S1.id 1234 And the variable referenced as S1.gpa has the value 3.5 in its memory location. S1.gpa 3.5 9/11/2003 23 Objects as Attributes One class can use another class object to define an attribute. This makes the class a composite class. For example, we can define the advisor attribute of the student to be of Professor type rather than simple String type. There is no limit to the number of levels to which objects can be bundled inside of one another. 9/11/2003 24 8

Professor advisor; class Professor{ int EmpID; String name; String worksfor; Student studentadvisee; void advisestudent(); bool agreetoteachcourse ();... } // end Professor Objects as Attributes id : 1234 gpa : 3.5 9/11/2003 25 S1 P1 EmpID: 9383 name: Dr.Jones studentadvisee: Both objects exist separately in memory Each attribute is a reference to an object Reference Handles Objects as Attributes Advantages to designing composite classes: Professor attributes are encapsulated Avoids data redundancy and potential loss of data integrity If professor name changes, it only changes in the Professor class. If String had been used for advisor, all objects with that advisor would have to change the name as well as the Professor class. Student object can request other services of the Professor object (e.g. where the professor s office is located, what other classes the professor is teaching, etc.) 9/11/2003 26 Themes in OO development Abstraction Postpone implementation decisions. Creates fewer dependencies. Encapsulation Information hiding Keep external aspects (interface) separate from internal implementation details. Combining data and behavior (ADT) behavior is associated with the data. Behavior of a request depends on the type or class of the data. 9/11/2003 27 9

Themes in OO development Emphasis on object structure, not procedure structure Emphasis is on what an object is rather than how it is used. The use of an object changes more often than the behavior of an object. Hence, the system is more stable. Sharing Inheritance allows sharing of data and behavior. Easier to build libraries that can be shared across projects. Synergy (cooperation) There is synergy between OO features (Abstraction, encapsulation, classification, inheritance, polymorphism) 9/11/2003 28 10