1. Trang chủ
  2. » Công Nghệ Thông Tin

Overview of Object-Oriented Software Design and Java Programming potx

68 565 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 68
Dung lượng 176 KB

Nội dung

1 Overview of Object-Oriented Software Design and Java Programming Putting the Pieces Together! 2 Object-Oriented Design A technique for developing a program in which the solution is expressed in terms of objects self- contained entities composed of data and operations on that data. 3 Object Oriented Programming  Programmer thinks about and defines the attributes and behavior of objects.  Often the objects are modeled after real-world entities.  Very different approach than function-based programming (like C). 4 Reasons for OOP Abstraction Polymorphism Inheritance Encapsulation Software Engineering Issues 5 Objects to Classes • A class defines the pattern used when instantiating an object of that type. • A class generally contains private data and public operations (called methods). 6 Class: Object Types  A Java class is an object type.  When you create the definition of a class you are defining the attributes and behavior of a new type.  Attributes are data members.  Behavior is defined by methods. 7 Creating an object  Defining a class does not result in creation of an object.  Declaring a variable of a class type creates an object. You can have many variables of the same type (class). Instantiation 8 Superclass and Subclass • Inheritance enables us to define a new class (called a subclass) that inherits the properties of an already existing class. • The newly derived class is then specialized by adding properties specific to it. • The class being inherited from is the superclass. • The class that inherits properties is the subclass. 9 Defining Objects • An object-oriented program consists of many objects. • An object is composed of identity, state (attributes, data, and their current values) and behavior (operations) . 10 Identity, State, Behavior • Identity is the property of an object that distinguishes it from all other objects. • The failure to recognize the difference between the name of the object and the object itself is the source of many errors in object-oriented (OO) programming. [...]... of the class Car, i.e., they are each a type of car 15 Object example Audi 6 BMW Z3 Corvette Car Car Car • Notice that all objects are of the same type All objects are cars! 16 Classes and Objects • An object is an instance of exactly one class • • Corvette can not be an instance of a car class and an instance of a plane class at the same time An instance of a class, an object, belongs to that particular... Behavior • The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties • A property is an inherent or distinctive characteristic, trait, quality, or feature that contribute to making an object uniquely that object • We will use the word attribute, or data member, to refer to the state of an object 11 Examples of State • Properties... instance variables Example, Joe's car may have 4 gallons of gas in it while John's car has 10 gallons The amount of gas in each car may change without affecting the amount of gas in the any other cars All instances (objects) of a class will have a set of instance variables that are specific to that individual object The combination of the values of these instance variables is known as the object’s state... descriptions of objects • To make a car the manufacturer must first have a design from which to build the first car Then, once all the problems are worked out, the design is used to build all the cars of that model 14 Objects • An object is an instance of a class • If we have a class definition called Car, then we can think of Audi, BMW, and Corvette as each being an instance (object) of the class... instance methods • These can only affect that object's parameters, i.e., it’s instance variables • Example: If BMW has 4 gallons of gas and someone puts 6 more gallons of gas in his/her car, the car now has 10 gallons The amount of gas in Audi and Corvette is unchanged 29 Messages and Methods Car MaxSpeed MaxSpeed=155 NumCars = 3 turnOnHazard() addGass(amount) Audi 6 Car BMW Z3 Car Corvette Car MaxSpeed... Elevators travel up or down Vending machines accept coins Clocks indicate the current time Values • • • Current floor Number of coins deposited The number of minutes since the last hour 12 Identity, State, Behavior • • • • Behavior is how an object acts and reacts, in terms of state changes and interactions with other objects An operation is some action that one object performs upon another in order to elicit... getGasLevel():GasLevel 34 Object Oriented Programming • When writing object-oriented programs, first one must define the classes (like Car) • Then, while the program is running, the instances of the classes (objects) (such as Audi, BMW, Corvette in our example) are created 35 Object Oriented Programming - Benefits • An object can be written and maintained separately from the rest of the program, modularity • An... defined you can create as many instances of the class (objects from the class) as you would like • Once a blue print is completed for the 2004 Porsche 911, Porsche will use an assembly line to build as many instances of the 2004 Porsche 911 as they wish 18 Defining a class • Properties are variables which describe the essential characteristics of an object • • Properties of a car: color, model, make, how... is being sent The name of the method that object is to execute Any parameters (variables) needed by that method • • • For Humans Who the message is for What we want the person to do What information is needed to do it 26 Messages and Methods • In order to process a message, an object needs to have a method defined for the requested task • A method is a small, well-defined piece of code that completes... describe the essential characteristics of an object • • Properties of a car: color, model, make, how many doors, transmission type, direction of movement, etc Behaviors are methods that describe how the object behaves and how the properties may be modified • Behavior of a car: braking, changing gears, opening doors, moving forwards or backwards, etc 19 Instance variables • • • • • The class definition will . terms of objects self- contained entities composed of data and operations on that data. 3 Object Oriented Programming  Programmer thinks about and defines the attributes and behavior of objects.  Often. 1 Overview of Object-Oriented Software Design and Java Programming Putting the Pieces Together! 2 Object-Oriented Design A. object-oriented (OO) programming. 11 Identity, S ta te, Behavior • The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties • A

Ngày đăng: 31/03/2014, 20:20