1 / 19

Systems Analysis & Design Methods

Systems Analysis & Design Methods. VI OO first rules What is Object Orientation ?. Books:. Object Oriented Software Construction, Bertrand Meyer. Why rules ?. Consistency If everyone uses the same rules, different parts will work together well.

vinaya
Download Presentation

Systems Analysis & Design Methods

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. Systems Analysis & Design Methods VI OO first rules What is Object Orientation ?

  2. Books: • Object Oriented Software Construction, Bertrand Meyer VI OO first rules What is Object Orientation ?

  3. Why rules ? • Consistency • If everyone uses the same rules, • different parts will work together well. • different team members will understand each other designs better, less chance of misunderstandings • Less ways of solving the same problem • Waste less time discussing what the best solution is. VI OO first rules What is Object Orientation ?

  4. Why rules ? (continued) • Better code: • = simpler, cheaper systems, that can be adapted more quickly Remarks about this: If a system is constructed with other rules or in a non OO way and it is working well, it deserves your respect anyway. VI OO first rules What is Object Orientation ?

  5. Difference object-class • An object is an instance of a class. • A class describes some facts about its objects. • Example: If Antwerp is an object, then City could be its class. E.g. The Whitten book mixes up objects and classes. The writers also seem to be confused about the difference between objects and subclasses. VI OO first rules What is Object Orientation ?

  6. Difference object-class • Exercise: Fill in the blancs: VI OO first rules What is Object Orientation ?

  7. Complete class • A class at conception/analysis level should contain its attributes and its non- trivial methods. • Why ? : attributes and methods of a class change together and so they belong together. • Example: Account -balance: double +withDraw(amount: double) +transfer(amount: double, to: BankAccount) +getBalance(): double VI OO first rules What is Object Orientation ?

  8. Complete class • Exercise: What’s weird about this design ?: Transactions Account -balance: double +withDraw(from: Account, amount: double) +getBalance(): double +setBalance(amount: double) +transfer(amount: double, from: Account, to:Account) VI OO first rules What is Object Orientation ?

  9. Encapsulation/Data abstraction • If a class X is a client of class Y, the attributes of Y can be changed by X only by using methods explicitly created for this purpose. ( The attributes are generally private, the methods intended for clients have public or package visibility. Other methods are not public. ) VI OO first rules What is Object Orientation ?

  10. Modifiable properties • A mutable (modifiable) property is represented by an attribute. • An immutable property can give rise to subclasses if the number of values the property can take is limited. • Why? • attributes are modifiable but an object cannot change its class. • Example: Person Person -maritalState: MaritalState +getMaritalState(): MaritalState … MariedPerson Bachelor VI OO first rules What is Object Orientation ?

  11. Modifiable properties • Exercise 1 Suppose we want to model that some birds belong to a species that can swim, and others don’t. Is this okay ? Bird -canSwim: bool … VI OO first rules What is Object Orientation ?

  12. Modifiable properties • Exercise 2 Is this okay ? Person -birthDate: Calendar … +getAge() : double +marry(Person partner) … VI OO first rules What is Object Orientation ?

  13. Common code • Common code within a class should be put into one method which is then called at several places. • Why ? • The same modifications is preferably done only in one place -> otherwise: bug risk by forgetting one place • Example: see next slide VI OO first rules What is Object Orientation ?

  14. Common code • Example VI OO first rules What is Object Orientation ?

  15. Common code • Exercise: Enhance the code on the left: VI OO first rules What is Object Orientation ?

  16. Command-Query separation • 1. A method that returns a result, shouldn’t change any attribute. (query) • 2. A method that changes an attribute, should NOT return a result. (command) • Why ? • In general: A method should have one single responsibility. • You don’t expect a query to change an attribute (side effect). Sometimes you just want to query. If you do, and the method has a side effect, you have to undo the undesired side effect, which is awkward. • Example. Next slide. VI OO first rules What is Object Orientation ?

  17. Command-Query separation VI OO first rules What is Object Orientation ?

  18. Command-Query separation:(continued) When mixing commands and queries, you sometimes can save a line of code or two… BUT… VI OO first rules What is Object Orientation ?

  19. Command-Query separation:(continued) … what happens if you don’t need the side effect: VI OO first rules What is Object Orientation ?

More Related