Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 - 1 Chapter 1 Introduction to Object-Oriented Programming and Software Development.

Similar presentations


Presentation on theme: "Chapter 1 - 1 Chapter 1 Introduction to Object-Oriented Programming and Software Development."— Presentation transcript:

1 Chapter 1 - 1 Chapter 1 Introduction to Object-Oriented Programming and Software Development

2 Chapter 1 - 2 Objectives Understand the basic of object-oriented programming –Differentiate classes and objects. –Differentiate class and instance methods. –Differentiate class and instance data values. –Draw UML diagrams for classes and objects –Describe significance of inheritance in object-oriented programs Name and explain the stages of the software lifecycle

3 Chapter 1 - 3 What is an Object ? Real-world objects: –Concrete objects: Apple1, Car1, TV2, Teacher2, Student3, … –Conceptual Objects: 1, 2.3, Date1, Meeting2, point2, … Objects have: –Properties (attributes): color, weight, height, sex, name, speed, position,… –Capabilities (behaviors): can receive commands(, request, query) and respond (do actions) based on its internal states to change its internal state and/or external environment. The properties of an object constitutes its current state.

4 Chapter 1 - 4 What is a Software object ? a software bundle of data and functions used to model real-world objects you find in everyday life. In OOP, Software objects are building block of software systems –program is a collection of interacting objects –objects cooperate to complete a task –to do this, they communicate by sending “messages” to each other Software objects can model –tangible things: School, Car, Bicycle, –conceptual things: meeting, date –Processes: finding paths, sorting cards Note: Software objects are only abstraction of real-world objects; properties and behavior of irrelevance will not be modeled in software objects.

5 Chapter 1 - 5 What is a Java Object? In Java, an object consists of 0 or more fields and 0 or more methods. –Fields are used to model properties. –Methods are used to model capabilities. Fields are variables. –like the fields of a C struct. –An object without methods is equivalent to a C struct. A method is similar to a C function. –Normally, it will operate on the fields of the object. –These fields are accessible by name in the method. Java variables can not hold objects, but only references to them. –Object do not have a names. –Object are created only at runtime.

6 Chapter 1 - 6 Classes and Objects Current conception: –a java/software object  a real-life object, –e.g., a Java car  a real car Disadvantage: impractical to work with objects this way –may be indefinitely many (i.e., modeling all atoms in the universe) –do not want to describe each individual separately, because they may have much in common Classifying objects into classes of similar properties/behaviors –factors out commonality among sets of similar objects –lets us describe what is common once –then “stamp out” any number of copies later –Ex: Student: { S1, S2, S3 } Course:{C1,C2,C3} Teacher:{ T1,T2} – but not {s1, t1}, {s2, t2}, {c1,c2,c3,s3} Analog: –blueprint (class) –constructions (objects)

7 Chapter 1 - 7 What is a Java Class? In Java, a class is a template (textual description) of a set of similar objects. –All objects in the class have the same types of properties and the same set of capabilities. It defines the fields and methods that all objects in that class will have. –Classes have names. –Class appear in the text of your program. –A java program consists of a set of classes. A defined class is a Java Type, so you can have objects or variables of that type.

8 Chapter 1 - 8 Example class Person { // fields or properties int age ; String name ; Person father, mother ; Person[] : siblings // methods or behavior capability void eat( Food food) ; void play() ; void work() ; void sleep(); } //possible statements m1 = new Person(); p1 = new Person; p1.mother = m1;

9 Chapter 1 - 9 Classes and Objects In OOP, a running application is results of participating objects and their interactions. Similar objects are described or defined by the same (set of ) classes –properties  fields –behavior capability  methods An object is called an instance of its defined classes. –Ex: stusent1 is an instance of both class Student and Person and Object( 萬物 ).

10 Chapter 1 - 10 Graphical Representation of a Class The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. We use a rectangle to represent a class with its name appearing inside the rectangle. Example: Account Motorcycle

11 Chapter 1 - 11 Graphical Representation of an Object We use a rectangle to represent an object and place the underlined name of the object inside the rectangle. Example: SV198 This is an object named SV198.

12 Chapter 1 - 12 An Object with the Class Name : This notation indicates the class which the object is an instance. This tells an object SV198 is an instance of the BankAccount class. Example: SV198 : BankAccount

13 Chapter 1 - 13 Messages and Methods How do objects interact ? –message passing ; method requests/invocation/call To instruct a class or an object to perform a task, we –send a message (method call) to it. –the message must be understandable to the receiving classes or objects. i.e., –the receiving class or an object must possess a matching method to be able to handle the received message. Kinds of method: –A method defined for a class is called a class method, and –a method defined for all instances of a class is called an instance method. A associated value we pass to an object when sending a message is called an argument of the message. –e.g., p1.eat( apple1 ); // receiver.method ( argument …).

14 Chapter 1 - 14 Sending a Message deposit 250.00 Message deposit with the argument 250.00 is sent to a BankAccount object SV198. SV198 : BankAccount Rreceiver caller

15 Chapter 1 - 15 Sending a Message and Getting an Answer current balance getCurrentBalance() Ask for the current balance of this particular account. SV198 : BankAccount The current balance of SV198 is returned.

16 Chapter 1 - 16 Calling a Class Method maximum speed MobileRobot getMaximumSpeed() Ask for the maximum possible speed for all MobileRobot objects is returned.

17 Chapter 1 - 17 Class and Instance Data Values An object is composed of data values (for its properties) and methods. –Property has name, type and value –ex: int age = 10 ; –property name and type are static (time-invariant ) –property value may change with time. An instance data value is a value of one of its properties of an individual instance. –For example, each BankAccount object maintains its balance. A class data value is a value of some property of the whole class. –It is shared by all instances of the class. –Ex: minimum balance and average balance in Account class.

18 Chapter 1 - 18 SV098 : BankAccountSV211 : BankAccountSV129 : BankAccount Sample Instance Data Value current balance 908.55 1304.98 354.00 All three BankAccount objects possess the same current balance property. The actual dollar amounts (data value) are, of course, different.

19 Chapter 1 - 19 Sample Class Data Value SV098 : BankAccountSV211 : BankAccountSV129 : BankAccount current balance 908.55 1304.98 354.00 BankAccount minimum balance 100.00 There is one copy of minimum balance for the whole class and shared by all instances. This line is an instance-of relationship.

20 Chapter 1 - 20 Object Icon with Class Data Value When the class icon is not shown, we include the class data value in the object icon itself. SV129 : BankAccount current balance 908.55 minimum balance 100.00

21 Chapter 1 - 21 Class and object diagrams

22 Chapter 1 - 22 Inheritance Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. –design/programming by difference. –Features common to all classes are defined in the superclass. –The classes that inherit common features from the superclass are called subclasses. We also call the superclass an ancestor and the subclass a descendant.

23 Chapter 1 - 23 A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Checking Savings

24 Chapter 1 - 24 Inheritance Hierarchy An example of inheritance hierarchy among different types of students. Student Graduate Undergrad Commuting Law Resident Masters Doctoral

25 Chapter 1 - 25 Software Engineering Much like building a skyscraper, we need a disciplined approach in developing complex software applications. Software engineering is the application of a systematic and disciplined approach to the development, testing, and maintenance of a program.

26 Chapter 1 - 26 Software Life Cycle The sequence of stages from conception to operation of a program is called software life cycle. Five stages are –Analysis –Design –Coding –Testing –Operation and Maintenance –Update and Evolution


Download ppt "Chapter 1 - 1 Chapter 1 Introduction to Object-Oriented Programming and Software Development."

Similar presentations


Ads by Google