1 / 13

Programming Style

Programming Style. Chapter 14 Part 3: Implementation Object-Oriented Modeling and Design Byung-Hyun Ha bhha@pusan.ac.kr. Lecture Outline. Introduction Object-Oriented Style Reusability Extensibility Robustness Programming-in-the-large. Introduction.

dyre
Télécharger la présentation

Programming Style

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. Programming Style Chapter 14 Part 3: Implementation Object-Oriented Modeling and Design Byung-Hyun Ha bhha@pusan.ac.kr

  2. Lecture Outline • Introduction • Object-Oriented Style • Reusability • Extensibility • Robustness • Programming-in-the-large

  3. Introduction • The experienced programmer follows principles to make readable programs that live beyond the immediate need • Good style is important in all programming, but it is even more important in OO design and programming because much of the benefit of the OO approach is predicated on producing reusable, extensible, understandable programs

  4. Object-Oriented Style • Reusability • Extensibility • Robustness • Programming-in-the-large

  5. Reusability • Kind of reusability • Sharing of newly-written code within a project • Reuse of previously-written code on new projects • Style rules for reusability • Keep methods coherent • Keep methods small • Keep methods consistent • Separate policy and implementation • Provide uniform coverage • Broaden the method as much as possible • Avoid global information • Avoid modes

  6. Reusability • Using inheritance • Subroutines • Factoring • Delegation • Encapsulate external code

  7. Extensibility • OO principles for extensibility • Encapsulate classes • Hide data structures • Avoid traversing multiple links or methods • Avoid cast statements on object type • Distinguish public and private operations

  8. Robustness • Guidelines for robustness • Protect against errors • User errors and low-level system errors • Programming bugs • Optimize after the program runs • Validate arguments • Avoid predefined limits • Instrument the program for debugging and performance monitoring

  9. Programming-in-the-large • Guidelines • Do not prematurely begin programming • Keep method understandable • Make methods readable • Use exactly the same names as in the object model • Choose name carefully • Use programming guidelines • Package into modules • Document classes and methods • Publish the specification

  10. Appendix: OO and Programming • We already discussed… • Farm • toString() and priority queue • Window programming • They cannot be possible without inheritance and polymorphism • If you want to prepare those functionalities in the examples, you should consider the use of OO concepts • Otherwise, your program will never be understandable (even for yourself), extensible, and reusable

  11. Appendix: OO and Programming • Inventory example • Inventory simulation • Assumptions • Two types of suppliers • Three types of demands • Two types of policies • Two ways of displaying results • If you want to carry out simulation for every possible combination of settings, you have to write 24 (= 2x3x2x2) programs • Too complex to write and manage • Let’s make them using one program (Inv_manage1.java) • How about it? • Could you understand? • Do you think you can easily extend the program?

  12. Appendix: OO and Programming • Inventory example (cont’) • Let’s use OO concepts (Inv_manage2.java, …) • First of all, easy to understand • Coherent, small, clear, consistent, extendible, reusable, … Inv_manage Supplier Demand Policy Display put_order today_deliever today_demand today_order show

  13. Appendix: OO and Programming • Tree example • Tree traversal with different purposes • Structural way (Tree1.java) • We should implement traversal algorithm every time we need • OO way (Tree2.java) • Don’t care about how to traverse, only need to write what to do 1 2 2 3 5 7 4 5 6 2 1 3

More Related