cs302 topic intro to object oriented pgmg
play

CS302 Topic: Intro. to Object Oriented Pgmg. Tuesday, Sept. 6, - PowerPoint PPT Presentation

CS302 Topic: Intro. to Object Oriented Pgmg. Tuesday, Sept. 6, 2005 Announcements Lab 1 due this Friday Lab 2 is now available (online) (due Friday, Sept. 16) Uses red-black trees Still in C Dont procrastinate!!!


  1. CS302 Topic: Intro. to Object Oriented Pgmg. Tuesday, Sept. 6, 2005

  2. Announcements � Lab 1 due this Friday � Lab 2 is now available (online) (due Friday, Sept. 16) � Uses red-black trees � Still in C � Don’t procrastinate!!! Finish Lab 1 early, then get early start on Lab 2. � This week’s lab meetings will discuss Lab 2 assignment � ☺ Today’s m ovie case study : Movies of swarms, and relationship to OOP ☺

  3. Computational Models � Modeling is an essential part of many disciplines in science and engineering, including software engineering � The importance of having a “good” model increases with the complexity of the project

  4. Computational Models � A model is a simplification of reality � Main reason for developing models: � Understanding the system being developed � We build models of complex systems because we cannot comprehend such a system in its entirety

  5. Principles of Modeling � The choice of the model has a significant impact on how the problem is approached and how a solution is devised � A model can be expressed at different levels of precision � A good model is connected to reality � A single model is not sufficient to represent most systems; A set of nearly independent models are required

  6. Models in Software Engineering � A modeling technique suitable for the programming approach should be used � Since object-oriented approach has proven to be superior to other approaches, models designed for this approach are widely used in software engineering

  7. Basic Principles of Object Orientation � Abstraction � Encapsulation � Modularity � Hierarchy � Inheritance

  8. What is Abstraction? � A model that includes most important aspects of a given problem while ignoring less important details An example of an item purchasing abstraction: Counter Items Queue

  9. What is Encapsulation? � Hide implementation from clients • Clients depend on interface

  10. What is Modularity? � The breaking up of something complex into manageable pieces or modules Queue Canteen System Order Placement Delivery Billing

  11. What is Hierarchy? � Level of abstraction Increasing Art abstraction Music Films Sculptures R&B Rap Decreasing Sci-Fi Action … Abstraction

  12. What is Inheritance? � Process by which one object acquires properties of another object � Supports concept of hierarchical classification � With inheritance, object only needs to define what makes it unique within its class � In OOP, Inheritance means inheriting another object’s interface, and possibly its implementation

  13. Example of Interface Inheritance � Suppose you want to define Search_Object_1 that: � Stores (key, value) pairs � Allows values to be looked up using keys � Supported operations for Search_Object_1: � insert: Adds a (key, value) pair to the object � delete: Deletes a (key, value) pair from the object � lookup: Given a key, retrieves the value associated with that key from the object � Later, define new object (Search_Object_2) that additionally allows traversing (key, value) pairs in sorted order � Supported operations for Search_Object_2: � All of above, plus: � rewind: returns us to beginning � next: returns next (key, value) pair � Accomplish this by having Search_Object_2 inherit Search_Object_1’s interface

  14. Example of Implementation Inheritance � Suppose: � Search_Object_1 is implemented using binary search tree � You already have a binary search tree implemented, including implementations for the previous operations, but using different names � To inherit binary search tree implementation, we make Search_Object_1 be a subclass of the binary tree. � We then make the insert, delete, and lookup operations call the appropriate binary tree operations

  15. But, there’s a problem with Implementation Interface… � Remember: � Object is supposed to hide its implementation � Implementation should be interchangeable with other objects that implement the same interface � Problem: � Search object’s interface is tied to the binary search tree’s interface � By making search object inherit from binary search tree, we’ve also made its implementation dependent on the binary tree � NOT GOOD!! � � Nearly always best to only inherent interface

  16. More detailed look at Object Orientation… 1. Object 2. Class 3. Attributes 4. Operation 5. Interface (Polymorphism) 6. Generalization Relationships

  17. 1. What is an Object? � An object is a “smart” data structure � Set of state variables � Set of methods for manipulating state variables � Examples – physical, conceptual, or software entities: � Physical entity: robot � chemical process Conceptual entity: � Software entity: linked list data structure

  18. Objects (con’t.) � An object advertises: � The types of data it will store � The types of operations it allows to manipulate its data (i.e., its interface) � An object hides: � Its implementation of the above � An object is something that has: � State � Behavior (i.e., operations) � Identity

  19. An Object Has State � The state of an object is one of the possible conditions in which an object may exist � The state of an object normally changes over time � Represented by: Attribute values + Links (relationship instances) Object: L. Parker Name: L. Parker Employee ID: 9738239 Date hired: Aug. 1, 2002 Teaching Status:

  20. An Object Has Behavior � Behavior determines how an object acts and reacts to requests from other objects � Behavior is represented by the set of messages it can respond to (i.e., the operations the object can perform) Add me to CS302 with L. Parker (Returns: confirmation) Registration System CS302 Course

  21. Representing Objects � As an example, we can represent an object as rectangles with underlined names : Professor L. Parker Class Name Only Object Name Only L. Parker : Professor Class and Object Name

  22. English 102 Physics 135 Math 241 CS 311 Example: Objects CS302 CS 140 CS102

  23. 2. What is a Class? � A class is a description of a group of objects with common properties (attributes), behavior (operations), relationships, and semantics � An object is an instance of a class � A class is an abstraction in that it: � Emphasizes relevant characteristics � Suppresses other characteristics

  24. The Relationship Between Classes and Objects � A class is an abstract definition of an object • It defines the structure and behavior of each object in the class • It serves as a template for creating objects � Objects may be grouped into classes � A particular object of a class is an instance Professor Professor Parker Professor Thomason Professor Berry

  25. Sample Class • Class Course Properties Behavior Name Add a student Location Delete a student Days offered Get course roster Credit hours Determine if it is full Start time End time

  26. Representing Classes � As an example, we can represent a class using a compartmented rectangle Professor

  27. Class Compartments � For example, we can represent a class as being comprised of three sections: • The first section contains the class name • The second section shows the structure (attributes) • The third section shows the behavior (operations) Professor Name empID create() change() save() delete()

  28. Class Compartments (cont.) � The second and third sections may be suppressed if they need not be visible on the diagram Professor Professor Professor Professor Name Name empID empID create() create() change() change() save() save() Professor delete() delete()

  29. English 102 Physics 135 Math 241 CS 311 CS 140 CS102 CS302 Example: Class CourseOffering

  30. � How many classes can you see? Classes of Objects

  31. 3. What is an Attribute? Object Class :CourseOffering Attribute Number=CS311 Attributes values startTime=1540 endTime=1655 CourseOffering :CourseOffering Number startTime Number=CS302 endTime startTime=1410 endTime=1525

  32. 4. What is an Operation? CourseOffering Class addStudent deleteStudent getStartTime getEndTime Operations

  33. 5. What is Polymorphism? � The ability to hide many different implementations behind a single interface OO Principle: Manufacturer A Encapsulation Manufacturer B Manufacturer C

  34. 5. (con’t.) What is an Interface? � A named set of operations that characterize the behavior of an element. � The interface formalizes polymorphism <<interface>> Triangle Polygon draw Square move scale rotate Pentagon

  35. 6. Relationships: Generalization � A relationship among classes where one class shares the structure and/ or behavior of one or more classes � Defines a hierarchy of abstractions in which a subclass inherits from one or more super classes � Single inheritance � Multiple inheritance � Generalization is an “is-a-kind of” relationship

  36. Example: Single Inheritance � One class inherits from another Ancestor BankAccount Superclass balance (parent) name number Generalization Withdraw() Relationship CreateStatement() Subclasses Current Savings Withdraw() GetInterest() Withdraw() Descendents

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend