Oosad 04
Upcoming SlideShare
Loading in...5
×
 

Oosad 04

on

  • 1,096 views

 

Statistics

Views

Total Views
1,096
Views on SlideShare
1,096
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Oosad 04 Oosad 04 Presentation Transcript

  • Object Oriented Concepts Chapter 04
  • The four basic OO concepts• Class – software abstraction of an object, including data and functionality• Object – person, place, thing, event, concept, screen, or report• Attribute - variable• Method – function or procedure
  • • It is optional in UML to show attributes and methods of a class• There are two types of attributes – Instance attributes – applicable to a single object – Static attributes – applicable to all instances of a single class – Underlined• Instance methods – operate on a single instance – Enroll a student• Static methods – operate on all instances – Search
  • Abstraction, Encapsulation and Information Hiding• Abstraction – Process of including features, attributes and methods that are of interest to your application and ignore the rest – It is an analysis issue that deals with what a class knows or does – Depends on the context in which you define the abstraction – The act of defining the interface of something – Act of painting a clear box around something
  • Encapsulation• Deals with – how you intend to modularize the features of a system. – How functionality is included is compartmentalized within a system• You can build anything you want and then you can later change the implementation and it will not affect other components within the system• Act of painting the box black• Define something is going to be done, but you are not telling the rest of the world how you are going to do it
  • Information Hiding• Restricting access to data attributes and some methods, to make your application maintainable• If one class wants information about another class, it should have to ask for it, instead of taking it.• Prevents highly coupled codes
  • Inheritance• Two or more classes often share the same attributes and/or methods• Don’t need to write same code repeatedly• Models “is a” and “is like” relationships• Enables you to reuse existing data and code easily• E.g. – STUDENTS have names, addresses and telephone numbers, vehicles • PROFESSORS have also the same• Create a class PERSON having those attributes and make STUDENT and PROFESSOR inherit from it• Everything a superclass knows the subclass knows or does it for free
  • Modeling Inheritance• Line with closed arrowhead Class A (the super class)• B inherits from A Class B (The subclass)
  • Inheritance Tips and Techniques• Look for similarities• Look for existing classes• Follow the sentence rule• Avoid implementation inheritance
  • Single and Multiple Inheritance• Single – when a class inherits from only one other class, we call this single inheritance• Multiple – when a class inherits from two or more other classes
  • Single Inheritance Airplane Vehicle maximumAltitude maximumFuel maximumFuel maxiumumNumberOfPassengers maximumSpeed speed maximumNumberOfPassenger s accelerate numberOfEngines Decelerate speed accelerate bank climb decelerate decend Airplane Car Car maximumAltitude make maximumSpeed modelmake numberOfEnginesmaximumFuelmaxiumumNumberOfPassengersmodel bankspeed turn Climb decendacceleratedecelerateturn
  • FishwingSpantype Multiple Inheritancenameeat Lizardfly Fish maximumSpeed wingSpan scaleColors Type numberOfLegsLizard eat eatnumberOfLegs fly flyscaleColorsmaximumSpeedeatfly AmphibianAmphibian namemaximumSpeed jumpname swimnumberofLegsscaleColorsjumpSpan jumpeatswim
  • Abstract and Concrete Classes• Abstract classes are in italics• Difference – objects are instantiated from concrete classes, but not from abstract classes• Your software will instantiate airplane and car objects but will never create vehicle objects
  • Association• Exist between objects – Students TAKE courses, professors TEACH courses – Criminals ROB banks etc…• Identify the relationship and describe it – Students TAKE courses • How many students?, How many courses? Etc – Identify the Cardinality and Optionality • Multiplicity
  • Modeling Associations UML multiplicity indicators• Thin line connecting two classes Indicator Meaning• Depict three things 0..1 Zero or one – Label 1 One only – Cardinality 0..* Zero or more – Role 1..* One or more n Only n (where n>1) Zero to n (where 0..n n>1) One to n (where label 1..n Cardinality A n>1) Cardinality B Class A role A role B Class B
  • 0..* 1..* 0..* consists of 1 Student student registers Semester Courseteaching 0..1 0..*assistant assists manager 0..1 0..1 holds 1 Employee Position manages 0..* staff member
  • How associations are Implemented• Associations are maintained through combination of attributes and methods• The attributes store the information necessary to maintain the relationship and methods keep the attributes current• Students would have an attribute takes, array that stores information of courses the student is currently taking – Add Course, Remove Course• Course may have attribute student – Add Student, Remove Student
  • Aggregation• Models “is part of” association – An airplane is made up of fuselage, wings, engines, landing gear, flaps and so on. – A delivery Shipment contains one or more packages• Modeling aggregation – Diamond , also model multiplicity and roles – Two way association – Two flavors • Hollow diamond – • Solid diamond – indicates composition, strong form
  • Aggregation tips and techniques• Apply the sentence rule• It should be part in the real world• You should be interested in the part• Show multiplicity and roles• Aggregation is inherited
  • Collaboration & Messages• Collaboration occurs between objects when one object asks another for information or to do something.• Eg. The airplane collaborates with its engines to fly• Objects collaborate with one another by sending each other messages• Message is either a request to do something or a request for information• Messages are modeled in UML sequence diagram and UML collaboration diagrams• Discussed Later
  • Collaboration Tips and Techniques• Some sort of association must exist• A corresponding method must exist in the target object• There might be a return value• There may or may not be parameters• Messages show collaboration, not data flows• Sometimes the target needs to collaborate• Each method should do something• An object can collaborate with itself
  • aStudent: Student :Seminar :Course enrollStudent(aStudent) isStudentEligible(aStudent) GetSeminarHistory() seminarHistory EligibilityStatus EnrollmentStatus ()
  • Persistence• How to store objects to permanent storage• The values of the objects as well as information needed to maintain the relationships must be saved permanently• Also concerned with their retrieval and deletion• Two types of objects exist: Persistent and Transient• Persistent: Customer• Transient: Customer editing screen
  • Persistence Tips and Techniques• Business/domain classes are usually persistent• User Interface classes are usually transitory• You need to store both attributes and association
  • Persistent Vs Transitory Associations• Persistent associations are those that are permanent – Information to maintain it is saved – Eg. TAKE, TEACH• Transitory associations are not saved to permanent storage and usually involve at least one transitory objects – If you are not persisting the object then you wont be persisting its relationship with other objects
  • Class Exercise• Explain classes, attributes, methods and associations in your projects• What is multiplicity – Give example• When do we include Roles when we model associations, give example from your project point of view• Describe the implementation of associations in your project• Give two examples of flavors of aggregation• Give example for one rule in aggregation• What is collaboration and how is collaboration achieved?• What is the difference between persistence and transient objects, associations?
  • Customer 0..n 0..n Product 0
  • Exercise 2 a. To the whole object1. Object b. “Is part of” associations2. Class c. Result of instantiation3. Method d. Line with closed arrowhead4. Instance e. Definition of a object5. Static f. Asking for information6. Inheritance g. Function and procedure7. Association h. Line with diamond8. Collaboration9. Role i. Optional in association10. Label j. Object can be instantiated11. Abstract classes k. Thin line12. Concrete classes l. Access restriction13. Modeling inheritance m. Paint a box black14. Modeling aggregation n. Relation15. Modeling association o. Object cant be instantiated16. Information hiding p. Paint a box clear17. encapsulation q. To one object18. abstraction r. In case of recursion
  • Coupling• Measure of how much two items such as classes or methods are interrelated – Coupled: when one class depends on another class – Loosely Coupled: when one class interacts with another class but doesn’t know any of the implementation details of the other class – Highly Coupled: when one class relies on the implementation of the other class• High coupling is a major reason for maintenance• Increasing the coupling between two items may make sense for performance reasons
  • Coupling Tips and Techniques• Avoid high coupling if you can• Document high coupling thoroughly
  • Cohesion• Measure of how much an item, such as a class or method, makes sense• Method - Highly cohesive – it does one thing and one thing only – Enroll a student in a course• Small and cohesive methods that do one thing and on thing only are easier to understand and maintain• Highly cohesive class – one type of object and one type of object only – University Information System – Professors instead of employees
  • Polymorphism• You can treat instances of various classes the same way within your system.• You can send a message to an object without first knowing what type it is and the object will still do “the right thing”, at least from its point of view.• Eg. The poker game – Darn polymorphism• The different objects respond to the message in their own way• Eg: Polymorphism at the University – How the university handles the hiring of a new staff
  • Interface• Definition of a collection of one or more operation signatures• Implemented by classes and components• To implement an interface, a class or component must include methods that have the operation signatures defined by the interface• Eg. Class STUDENT implements the “Serializable” interface and the “Searchable” interface – The Lollipop notation – The box notation
  • Components• Modular, extensible unit of independent deployment that has contractually specified interfaces(s) and explicitly defined dependencies• Components should be modular, extensible, and open – Modular – components contains everything it needs to fulfill its responsibilities – Extensible – a component can be enhanced to fulfill more responsibilities than it was originally intended to – Open – it can operate on several platforms and interface with other components through a single programming interface• Component diagrams show the software components that make up a larger piece of software, their interfaces, and their interrelationships.• For the sake of our discussion, a components may be any large-grain item