OBJECT ORIENTED CONCEPTS

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

CMSC 202 Inheritance. Aug 6, Object Relationships An object can have another object as one of instance variables. The Person class had two Date.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Road Map Introduction to object oriented programming. Classes
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 Basic Object Oriented Concepts Overview l What is Object-Orientation about? l What is an Object? l What is a Class? l Constructing Objects from Classes.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Java Objects and Classes. 3-2 Object Oriented Programming  An OO program models the application as a world of interacting objects.  A typical Java program.
Object Oriented Software Development
Chapter 4 Objects and Classes.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Object Oriented Programming Concepts Fatih University Ceng-104-A Introduction to Object Oriented Programming Harun Reşit Zafer This is a slide version.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
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.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Classes 1 COMPSCI 105 S Principles of Computer Science.
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
Introduction to programming in the Java programming language.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Chapter 11 An introduction to object-oriented design.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Object Oriented Programming Object and Classes Lecture 3 MBY.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
Chapter 11 An introduction to object-oriented design.
Object-Oriented programming for Beginners LEAPS Computing 2015
Re-Intro to Object Oriented Programming
GC211 Data structure Lecture 3 Sara Alhajjam.
What is an Object Objects are key to understanding object-oriented technology. An object can be considered a "thing" that can perform a set of related.
Objects as a programming concept
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 21, 2011
Introduction to Programming G50PRO University of Nottingham Unit 9 : Classes and objects Paul Tennent
Concepts of Object Oriented Programming
Building Java Programs
Objects as a programming concept
Objects First with Java A Practical Introduction using BlueJ
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Objects as a programming concept
Chapter 11 Object-Oriented Design
Unified Modeling Language
Introduction to Unified Modeling Language (UML)
Object Oriented Programming
Object Oriented Concepts -I
Today’s Objectives Define the Problem Domain
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
PRG 420 NERD Education for Service-- prg420nerd.com.
What is an object? An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the.
Introduction to Computer Programming
Object-Oriented Programming
Object oriented vs procedural programming
Object-Oriented Programming
Session 2: Introduction to Object Oriented Programming
Object-Oriented Programming
Introduction to Object-Oriented Programming
Dr. R Z Khan Handout-3 Classes
Presentation transcript:

OBJECT ORIENTED CONCEPTS Chapter 2

Introduction In the real world, there are many individual objects all of the same kind. There may be thousands of cars, all of the same make and model. Each car was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your car is an instance of the class of objects known as cars. Many objects can be instantiated from a single class. Therefore a class is an abstract descriptor for a set of instances.

Class A class is the blueprint from which individual objects are created These objects have similar characteristics (common structure, common behaviour, common relationship and common semantics). Semantics is a set of rules that specify the meaning of syntactically legal construct in a programming language. Classes are sometimes referred to as entity classes or model class  

Class For example, a Car class may be used to represent the common state (e.g., make, model, colour, mileage, etc...) and behaviour (e.g., start, stop, changeGear, turn etc...) between all car objects a 2DShape class may represent common state (e.g., centerPoint, lineWidth) and behaviour (e.g., calculateArea, calculatePerimeter)  for 2D shapes.

Class CLASS : Car ATTRIBUTES Make Model Number of doors Engine size Another Example ATTRIBUTES Make Model Number of doors Engine size Colour METHODS Stop Turn Accelerate brake

TASK 1 List out the classes that you think are involve in the Student Information System?

CLASS Class table/notation is used to model the static structure of a system which is based on data it contains the name of class, attributes and methods Class name (singular) List of attributes List of methods

Class Class name A class Car represented in class notation. attributes make model doors bodyLength engineSize colour speed stop() turn() accelerate() brake() Class name A class Car represented in class notation. attributes methods

Implementation in Java The following codes implements a class car (it is just a blueprint that might be used in an application) : class car { String make = “ “; String model = “ “; int doors=0; int bodyLength = 0; int engineSize = 0; String colour = “ “; int speed = 0; void accelerate(int increment) { speed = speed + increment; } void brake(int decrement) { speed = speed - decrement; } }

Implementation in Java The following carDemo class will creates 2 car objects and invoke their methods: class carDemo { public static void main(String[] args) { // Create two different car objects car car1 = new car(); car car2 = new car(); // Invoke methods on those objects car1.accelerate(50); car2.brake(20) ; }

Objects Software objects are conceptually similar to real-world objects They too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages) attributes – they know things behavior (methods) - they do things

Objects object of the same type will have an identical set of attributes Attributes of one object may contain different data values from those of another object.

Objects Object can be considered as a container for a set of data and the operation that need to be performed on it. Properties are : It has a unique identity for the lifetime of the object Its data is in the form of a set of attributes, each has a value at any given point in time. A set of methods can be performed on the data It is an instance of a class

Objects Example - CLASS: car An instance (object) of the class car refers to a specific vehicle eg. Mercedes, Honda, BMW, Toyota

ATTRIBUTES Attributes are data items that define a class They are features/properties that help describes the system

TASK 2 List the attributes necessary for the class student

CLASS & OBJECTS Car BJ1132: car KN1123: car A Car class Car objects make model doors bodyLength engineSize colour speed stop() turn() accelerate() brake() BJ1132: car make=‘Ford’ model=‘Falcon’ doors=4 bodyLength=300 engineSize=6 colour=‘red’ speed=0 stop() turn() accelerate() brake() KN1123: car make=‘Toyota’ model=‘Corolla’ doors=5 bodyLength=200 engineSize=4 colour=‘white’ speed=100 stop() turn() accelerate() brake() A Car class Car objects Class Notation Object Notation/diagram

CLASS & OBJECTS There are 4 different types of methods/behaviour : Constructor methods – executed each time an instance of the class is created. Often used to initialise attributes. Mutator methods – methods which allow other objects to set or change the value(s) of an object attribute(s). This method begins with the word set e.g. setName. Accessor methods – methods which allow other objects to query the value(s) of a n object attribute(s). This method begins with the word get e.g.getName. Other methods – normally used to perform more complex operations e.g. calculation, validation

CLASS & OBJECTS Tips : To find class/objects/attributes, read the problem definition for nouns and noun phrases. (Not all nouns in the problem statement are vital to the solution) To identify methods, look at the verbs that describe the actions performed by the nouns

CLASS & OBJECTS Example: A program is required to process the employee pay. The employee data is read from a file. For each employee, compute the employee’s monthly pay and then print a report containing their detail together with their pay. The input file contains the employee number, pay rate, the number of hours worked and the overtime hours worked in a week. Assuming the overtime rate rate is 1.5 times the standard rate. Analyzed the above problem.

CLASS & OBJECTS EmployeePay empNumber payRate hoursWorked overtimeHrs Listing the attributes

CLASS & OBJECTS Example: A program is required to process the employee pay. The employee data is read from a file. For each employee, compute the employee’s monthly pay and then print a report containing their detail together with their pay. The input file contains the employee number, pay rate, the number of hours worked and the overtime hours worked in a week. Assuming the overtime rate rate is 1.5 times the standard rate. Analyzed the above problem.

CLASS & OBJECTS EmployeePay empNumber payRate hoursWorked overtimeHrs readData() printDetail() calcPay() printPay() Listing the methods