1 / 34

Title Slide

Java Programming Object Oriented Methodology By Ralph B. Bisland, Jr. Title Slide. CSC 444. A strategy for organizing systems as collections of interacting objects that combine data and behavior. Object Oriented Methodology Object Oriented Design Object Oriented Programming

rogerb
Télécharger la présentation

Title Slide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Programming Object Oriented Methodology By Ralph B. Bisland, Jr. Title Slide CSC 444

  2. A strategy for organizing systems as collections of interacting objects that combine data and behavior. Object Oriented Methodology Object Oriented Design Object Oriented Programming Object Oriented Testing What Is Object Orientation?

  3. Procedural Method: Developer concentrates on developing code that mimics the procedure to represent the real world system. Object Oriented Method: Developer concentrates on developing representations of real world objects, their actions, and how they relate to each other. Developing Programs

  4. An object is a software “bundle” of data and procedures that act on the data. A procedure is called a “method”. Objects are the heart of OOM. Objects share two common characteristics State: What an object is currently “doing” Behavior: What can an object do Objects

  5. A Lion: States Color Weight Tired? Hungry? Behaviors Sleep Hunt Roar Example Of Objects

  6. A Car States Current Speed Type of Transmission 2/4 Wheel Drive Lights On Current Gear Behaviors Turning Breaking Accelerating Another Object

  7. A Baseball Player States Batter Pitcher Behaviors Batting Average Earned Run Average One More

  8. Pictorial View Of A Class Message Response Methods Data

  9. An object is an instance of a class. Classes must be instantiated to produce objects. Examples: FordMustang = new Car ChevyCorvette = new Car Each object usually has different values for its instance variables. Objects

  10. The Car Object Break Accelerate Steer Change Gears Toggle Lights Methods 75 mph 4th Gear Lights On Data

  11. To create an individual object, a class must be instantiated. Example: myCar=new Car (75mph, 4thgear, lightson) yourCar=new Car (60mph, 1stgrear, lightsoff) Use the methods to manipulate the instance variables. myCar.Accelerate(+15) yourCar.Accelerate(-10) Creating Objects

  12. The process of packaging an object’s data and methods together. Objects consist of a public interface (external) and a private (internal) section. The internal portion has more limited visibility than the external portion. Safeguards the object against unwarranted external access. Can only communicate with the object through its interface. Encapsulation

  13. Implementation Hiding : Protection of the internal implementation of object. The internal data and methods are the parts of the object hidden from other objects. Major benefit: Pata and methods can be changed without affecting other objects. Modularity: An object can be maintained independently of other objects. Also easier to distribute objects through the system. Benefits Of Encapsulation

  14. How software objects interact and communicate with each other. Analogy: Two people communicating with each other. Person 1 to person 2: “Come here, please”. Sometimes the message must contain additional information. This is done through message parameters. Messages

  15. Message: Accelerate the car by 15 mph. The object to receive the message: car The name of the action to perform: accelerate Any parameters the method requires: 15 mph Message passing is accomplished through method calling. Messages and methods are synonymous. Messages can be sent to objects in another location: Distributed Object Example

  16. A class is a template (or prototype) for an object. Analogy: A class is to an object is what a blueprint is to a house -- many houses can be built from the same blueprint. A blueprint outlines the makeup of a house. An object is an instantitation of a class. Classes can not be used by themselves. There may be many different instances of a class. Many cars, many lions, etc. Classes

  17. Benefits of objects: modularity and information hiding. Benefits of classes: reusability. Each instance of a class has it’s own state variables, but share methods. State variables of the instance of a class are called “instance variables”. Classes (ctd)

  18. What happens if an object is basically the same as other objects, but it has a few slight differences? Inherit the basic characteristics from a super class and form a sub class (AKA: parent-child classes). Inheritance: The process of creating a new class with the characteristics of an existing class, along with additional characteristics unique to the new class. Inheritance

  19. When a subclass inherits from a superclass, it inherits all of the superclass state variables and the methods. Additional methods and/or state variables can be added to the subclass. Inheritance (ctd)

  20. Class: car Basic data Number of wheels Number of doors Types of Cars Gas powered Fuel tank capacity MPG Electric Powered Size battery Example

  21. Inherited methods can be overridden Different code can be supplied in the methods for each subclass. Example: Gas powered cars can accelerate faster than electric powered cars, so the acceleration routine might be different. Inherited Methods

  22. Class: Figure Rectangle State Variables: Length, Width Methods: Calculate_Area Circle: State Variables: Radius Method: Calculate_Area Another Example

  23. Inheritance Tree Car Gas Powered Electric Powered 4-Cylinder 6-Cylinder

  24. Sometimes it is useful to create superclasses that act purely as templates for more subclasses. The superclass serves as nothing more than an abstraction for the common class functionality shared by its subclasses. Called abstract classes. Abstract classes can not be instantiated - an object can not be created from it. Abstract Classes

  25. Reason: Parts of it are yet to be defined. Parts of methods have yet to be implemented - abstract methods. The actual implementation of the method is defined in the subclass. Abstract Classes (ctd)

  26. Acceleration method can not be defined until the acceleration capabilities are known. How a car accelerates is determined by the type of engine it has. Engine type is unknown in the superclass Child class would implement the specific acceleration method to reflect the acceleration capabilities of their respective engines. Example

  27. Class: Baseball Player Subclasses: Batter and Pitcher All baseball players have some basic data: Team, Uniform#, Birthdate, etc. All baseball players have some basic methods: ComputeAge, TaxComputations, etc. Another Example

  28. Batters have some specific data: Atbats, Hits, Homeruns, etc. Batters have some specific methods: CalculateBattingAverage, CalculateSluggingPercentage, Etc. Pitchers have some specific data: NumbOfWins, NumbOfLosses, InningsPitched, EarnedRuns, etc. Pitchers have some specific methods: CalculateERA, etc. Another Example (ctd)

  29. Example (ctd) Baseball Player Class Player Name, Team Name Uniform#, Birthdate CalculateAge CalculateTaxes Batter Subclass Pitcher Subclass NumberOfWins, NumberOFLosses, InningsPitched, EarnedRuns CalculateERA AtBats, Hits, HomeRuns CalculateBattingAverage, CalculateSP

  30. It doesn’t make sense to create (instantiate) a Baseball Player object from the Baseball Player class (the abstract class). We must create an object of the subclasses, Batter or Pitcher (which inherits from the super class Baseball Player) Example (ctd)

  31. Enables a subclass to inherit characteristics from more than one superclass. Example: A whale inherits some characteristics from mammals and some from fish. Multiple Inheritance

  32. Means “having many forms”. Describes an elegant and relative simple technique by which a reference that is used to invoke a method can actually invoke different methods at different times, depending upon the nature of the invocation. Accomplished by late binding of the class type to the method. Polymorphism

  33. Assume a superclass of “figure” which has a method called computeArea. Assume several subclasses of “figure”. Examples: Square, Triangle, Circle, etc. The method of computing the area of a figure is different for each different type of figure. Example

  34. Since Square, Triangle, etc. are subclasses of figure, they can be assigned into figure. The method computeArea can be passed the value figure. figure = square (associated data) computeArea (figure) The correct method for computing the area is then executed because of late binding (binding at run time). Example (ctd)

More Related