1 / 9

Object Oriented Program Terms

***** SWTJC STEM *****. An object is a fundamental entity in a Java program. OO ( O bject O riented) programming has been around since the 1960’s in one form or another. In 1980’s and 1990’s it’s popularity increased enormously with the introduction of C++ and then Java.

duane
Télécharger la présentation

Object Oriented Program Terms

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. ***** SWTJC STEM ***** • An object is a fundamental entity in a Java program. • OO (Object Oriented) programming has been around since the 1960’s in one form or another. • In 1980’s and 1990’s it’s popularity increased enormously with the introduction of C++ and then Java. • One reason for its popularity is that objects can represent real world entities like an employee in a company or a bank account. • You might be asked to write a procedure oriented program to balance a bank account. When finished, it would do just that the one task. • By creating the bank account as an object, you create a program that can capture many more aspects. In addition to balancing the account, you could also handle service charges or interest, post a check, etc. Object Oriented Program Terms Chapter 2-1 cg 17

  2. ***** SWTJC STEM ***** • The terms you need to know in OO programming include: • object • attribute • method • class • encapsulation • inheritance • polymorphism • We will study these terms in greater detail as the course progresses. For now, we will use very brief definitions. Object Oriented Program Terms Chapter 2-1 cg 17

  3. ***** SWTJC STEM ***** • object – The fundamental element in an OO program. • attribute – Object values that are stored internally. Attributes “remember” the states or properties of the object. • method – A group of programming statements, given a name, and executed when invoked. Methods define the behaviors of the object. • class – The model from which the object is created. The class defines the properties (states) and behaviors of the object. • encapsulation – A object protects and manages its own properties. Other objects cannot “reach in “ and change an objects properties. • inheritance – The definition of one class can be based on another class, creating a hierarchy of classes. • polymorphism - The ability of different objects to respond differently to the same message. Object Oriented Program Terms Chapter 2-1 cg 17

  4. ***** SWTJC STEM ***** Procedure Oriented Solution Cylinder Volume Calculate Volume of Cylinder V = PI * r2*h Radius r Cylinder Volume Height h Note that the solution does only one thing, calculate V. Chapter 2-1 cg 18

  5. ***** SWTJC STEM ***** Object Oriented Solution Cylinder Volume Cylinder Object Attributes r radius h height V volume ----------------------- Methods Set r, h Get r, h, V Messages to/from ObjectsetRadius(5) setHeight(10) getRadius( ) returns 5 getHeight( ) returns 10 getVolume( ) returns 785 Chapter 2-1 cg 18

  6. ***** SWTJC STEM ***** Messages to/from ObjectsetRadius(5) setHeight(10) getVolume( ) returns 785 emptyTank( ) getTotal( ) returns 0fillTank( ) getTotal( ) returns 785 emptyTank( ) add(100) getTotal( ) returns 100 add(50) getTotal( ) returns 150 remove(80) getTotal( ) return 70 Tank Object Object Oriented Solution Cylindrical Tank Simulation Attributes r radius h height V volume T total liquid ----------------------- Methods set r, h get r, h, V, T empty, fill add, remove Chapter 2-1 cg 18

  7. ***** SWTJC STEM ***** • The PO program does only thing, calculate volume. • The OO program does many things. • It would take several PO programs packaged together (to make them accessible) to accomplish the same thing. • Methods of an OO program are actually PO programs collected together and organized to make them readily accessible. • This fact is why we will study and use many of the principles of PO programming when developing OO programs. • Before proceeding, we need to talk about two more concepts: • Programsyntax and semantics • Programerrors In Summary Chapter 2-1 cg 18

  8. ***** SWTJC STEM ***** • Syntax refers to the rules for writing a program statement. • These rules must be followed in creating a program. • Example: “prntln” is bad syntax. Why? • “prntln” is missing the “i” and should be “println”! • Appendix L of the text defines the syntax rules of Java. • JBuilder will often help you find incorrect syntax before you execute the program. • The semantics of a program statement defines what will happen when the statement is executed. • Programming languages are generally unambiguous, which means there is one and only one interpretation of a statement. • The question is whether the interpretation is the one you wanted. If not, the program may do something you did not intend. Syntax and Semantics Chapter 2-1 cg 19

  9. ***** SWTJC STEM ***** • A computer program may have problems that prevent it from executing correctly. • These problems, or errors, take three forms: • syntax errors (compile-time) • Spelling “println” wrong is a syntax error. • JBuilder generally finds these. • semantic errors (run-time) • Dividing by zero happens at run time and is a semantic error. • Semantic errors usually cause a program to terminate abnormally. • logic errors • Program executes but produces incorrect results. • Programs must be tested thoroughly and “debugged” Computer Program Errors Chapter 2-1 cg 20

More Related