1 / 36

Basic Concepts Introduction to OO Development and Software Engineering Principles

Basic Concepts Introduction to OO Development and Software Engineering Principles. SYSC 3100 - System Analysis and Design. Everything is an Object!. You, me, your neighbour , desks, chairs, doors, etc. Some of these things are the same, and some of them are different.

cybele
Télécharger la présentation

Basic Concepts Introduction to OO Development and Software Engineering Principles

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. Basic Concepts Introduction to OO Development andSoftware Engineering Principles SYSC 3100 - System Analysis and Design

  2. Everything is an Object! • You, me, your neighbour, desks, chairs, doors, etc. • Some of these things are the same, and some of them are different. • Some of them are “active”, and others are “passive”.

  3. Objectives • Define objects, attributes and operations. • Differentiate between OOA, OOD and OOP (!) • Describe a Class and an object. • Define information hiding and encapsulation. • Define generalization and specialization and the isA rule. • Define polymorphism and over-riding. • Describe active objects and persistence.

  4. Object-Oriented Development (OOD) • Objects are abstractions of real-world or system entities and manage themselves • Objects are independent and encapsulate state and representation information (attributes). • System functionality is expressed in terms of object services (operations) • Shared data areas are eliminated. Objects communicate by message passing • Objects may be distributed and may execute sequentially or in parallel

  5. Objects, Attributes, Operations

  6. O-O World View • An object-oriented system is regarded as a network of cooperating objects which • interact by sending each other messages • maintain their own state • have an individual identity

  7. Advantages of OOD • Easier maintenance. Classes may be understood as stand-alone entities, including their own functionality and data • Classes are appropriate reusable components • For some systems, there may be an obvious mapping from real world entities to system classes, e.g., accounts in banking system

  8. Object-oriented development • Object-oriented analysis (OOA), design (OOD) and programming (OOP) are related but distinct • OOA is concerned with developing an object model of the application domain • OOD is concerned with developing an object-oriented system model (structure, behaviour) to implement requirements • OOP is concerned with realising an OOD using an OO programming language such as Java or C++

  9. Principal Concepts • Objects, classification • encapsulation and information hiding • modularity • generalization and inheritance • typing • polymorphism • dynamic binding • concurrency • persistence

  10. Classes and Objects • Object • A chunk of structured data in a running software system • Has properties • Represent its state • Has behaviour • How it acts and reacts • May simulate the behaviour of an object in the real world • Has an identity: each object is unique

  11. High-level Examples Class Identity Behaviour State Studying, resting, qualified. Person. ‘Hussain Pervez.’ Speak, walk, read. My favourite button white denim shirt. Pressed, dirty, worn. Shirt. Shrink, stain, rip. Sale. Sale no #0015, 16/06/02. Earn loyalty points. Invoiced, cancelled. Bottle of ketchup. This bottle of ketchup. Spill in transit. Unsold, opened, empty.

  12. Objects Jane: date of birth: 1955/02/02 address: 99 UML St. position: Manager Savings Account 12876: Greg: balance: 1976.32 opened: 1997/03/03 date of birth: 1970/01/01 address: 75 Object Dr. Margaret: date of birth: 1980/03/03 Mortgage Account 29865: address: 150 C++ Rd. position: Teller balance: 198760.00 opened: 2000/08/12 Transaction 487: property: 75 Object Dr. amount: 200.00 time: 2001/09/01 14:30 Instant Teller 876: location: Java Valley Cafe

  13. Classes • A class: • Is a unit of abstraction in an object oriented analysis, design, or program • Represent instances of real-world and system entities • Represents similar objects • Its instances • Is a kind of software module • Describes its instances’ structure (properties) • Contains operations/methods to implement their behaviour

  14. Classes and Objects: Example

  15. Encapsulation and Information Hiding Encapsulation: The technique of hiding details which are not needed by the user of an abstraction Applied in object-oriented systems by the separation of object interfaces and bodies A_STACK interface PUSH POP client’s view body

  16. Message-passing and Encapsulation ‘Layers of an onion’ model of an object: Message from another object requests a service. Operation called only via valid operation signature. An outer layer of operation signatures… Data accessed only by object’s own operations. …gives access to middle layer of operations… An object’s data ishidden (encapsulated). …which can access inner core of data

  17. Object-Oriented Computation Model system operation control flow data flow #1 draw #2 insert print Attributes #1 remove update Attributes #4 #3 insert #4 clear Attributes #2 Attributes #3 remove draw-line

  18. Organizing Classes into Inheritance Hierarchies • Superclasses • Contain features common to a set of subclasses • Inheritance hierarchies • Show the relationships among superclasses and subclasses • Inheritance • The implicit possession by all subclasses of features defined in its superclasses

  19. An Example Inheritance Hierarchy • Inheritance • The implicit possession by all subclasses of features defined in its superclasses

  20. Generalization and Specialization • Classification is hierarchic in nature • Generalization: the technique of factoring out common properties into shared classes • facilitates reuse and change control • the reverse operation is the specialization • For example, a person may be an employee, a customer, a supplier of a service • An employee may be paid monthly, weekly or hourly • An hourly paid employee may be a driver, a cleaner, a sales assistant

  21. Specialization Hierarchy More general (superclasses) Person Employee Customer Supplier monthly paid weekly paid hourly paid More specialized (subclasses) Sales assistant Driver Cleaner

  22. The Isa Rule • Always check generalizations to ensure they obey the “isa” rule • “A checking account is an account” • “A village is a municipality” • Should ‘Province’ be a subclass of ‘Country’? • No, it violates the isa rule • “A province is a country” is invalid!

  23. Inheritance hierarchy of mathematical objects

  24. Make Sure all Inherited Features Make Sense in Subclasses

  25. Methods, Operations and Polymorphism • Operation • A higher-level procedural abstraction that specifies a type of behaviour • Independent of any code which implements that behaviour • E.g., calculating area (in general) • Operations are defined during Analysis and Design • They are implemented with methods

  26. Methods, Operations and Polymorphism • Method • A procedural abstraction used to implement the behaviour of a class. • Several different classes can have methods with the same name • They implement the same abstract operation in ways suitable to each class • E.g, calculating area in a rectangle is done differently from in a circle

  27. Polymorphism • A property of object oriented software by which an abstract operation may be performed in different ways in different classes. • Requires that there be multiple methods of the same name • The choice of which one to execute depends on the object (i.e., type) that is in a variable, on which the method is executed • Reduces the need for programmers to code many if-else or switch statements

  28. Overriding • A method would be inherited, but a subclass contains a new version instead • For restriction • E.g. scale(x,y) would not work in Circle • For extension • E.g. SavingsAccount might charge an extra fee following every debit • For optimization • E.g. The getPerimeterLength method in Circle is much simpler than the one in Ellipse

  29. How a decision is made about which method to run • If there is a concrete method for the operation in the current class, run that method. • Otherwise, check in the immediate superclass to see if there is a method there; if so, run it. • Repeat step 2, looking in successively higher superclasses until a concrete method is found and run. • If no method is found, then there is an error • In Java and C++ the program would not have compiled

  30. Dynamic binding • Occurs when decision about which method to run can only be made at run time • Needed when: • A variable is declared to have a superclass as its type, and • There is more than one possible polymorphic method that could be run among the type of the variable and its subclasses

  31. Abstract Classes and Methods • An operation should be declared to exist at the highest class in the hierarchy where it makes sense • The operation may be abstract (lacking implementation) at that level • If so, the class also must be abstract • No instances can be created • The opposite of an abstract class is a concrete class • If a superclass has an abstract operation then its subclasses at some level must have a concrete method for the operation • Leaf classes must have or inherit concrete methods for all operations • Leaf classes must be concrete

  32. Concurrency • The nature of objects as self-contained entities make them suitable for concurrent implementation. • There are two forms of objects in concurrent systems. • Passive: • operations execute only in response to external stimuli • call other objects only in response to external stimuli • Active • operations may execute asynchronously • has an independent thread of control • call other objects “spontaneously” • change state “spontaneously”

  33. Active transponder object • Active objects may have their attributes modified by operations but may also update them autonomously using internal operations • Transponder object broadcasts an aircraft’s position. The position may be updated using a satellite positioning system. The object periodically update the position by triangulation from satellites

  34. An active transponder object

  35. Persistence • The ability of an object to exist after the termination of the program which created it • Allows data storage in terms of objects (e.g. files are objects) • Provides a model for interaction with a DBMS or FMS • E.g., Java serialization, Object-oriented DBMS OO program Database

  36. Summary • An object is some “thing” which has attributes (variables) and operations that they can perform • A class is the blueprint or template that describes objects that have similar characteristics. • Big idea: hide implementation of objects to make it easy to change without affecting the world. • Polymorphism allows different types to implement common operations differently. • “Active objects” operate spontaneously and independently of each other (like us!).

More Related