oop review cs 124. object-oriented programming revisited key oop concepts object, class...
TRANSCRIPT
![Page 1: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/1.jpg)
OOP Review
CS 124
![Page 2: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/2.jpg)
Object-Oriented ProgrammingRevisited
Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses Abstraction Reuse Polymorphism, Dynamic Binding
Object-Oriented Design and Modeling
![Page 3: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/3.jpg)
Object
Definition: a thing that has identity, state, and behavior
identity: a distinguished instance of a class state: collection of values for its variables behavior: capability to execute methods
* variables and methods are defined in a class
![Page 4: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/4.jpg)
Class
Definition: a collection of data (fields/ variales) and methods that operate on that data
define the contents/capabilities of the instances (objects) of the class
a class can be viewed as a factory for objects a class defines a recipe for its objects
![Page 5: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/5.jpg)
Instantiation
Object creation Memory is allocated for the object’s fields as
defined in the class Initialization is specified through a constructor a special method invoked when objects are
created
![Page 6: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/6.jpg)
Encapsulation
A key OO concept: “Information Hiding” Key points
The user of an object should have access only to those methods (or data) that are essential
Unnecessary implementation details should be hidden from the user
In Java/C++, use classes and access modifiers (public, private, protected)
![Page 7: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/7.jpg)
Inheritance
Inheritance: programming language feature that allows for the
implicit definition of variables/methods for a class through an existing class
Subclass relationship B is a subclass of A B inherits all definitions (variables/methods) in A
![Page 8: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/8.jpg)
Abstraction
OOP is about abstraction Encapsulation and Inheritance are examples
of abstraction What does the verb “abstract” mean?
![Page 9: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/9.jpg)
Reuse
Inheritance encourages software reuse Existing code need not be rewritten Successful reuse occurs only through careful
planning and design when defining classes, anticipate future
modifications and extensions
![Page 10: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/10.jpg)
Polymorphism
“Many forms” allow several definitions under a single method name
Example: “move” means something for a person object but means
something else for a car object
Dynamic binding: capability of an implementation to distinguish between the
different forms during run-time
![Page 11: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/11.jpg)
Building Complex Systems
From Software Engineering:complex systems are difficult to manage
Proper use of OOP aids in managing this complexity
The analysis and design of OO systems require corresponding modeling techniques
![Page 12: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/12.jpg)
Object-Oriented Modeling
UML: Unified Modeling Language OO Modeling Standard Booch, Jacobson, Rumbaugh
What is depicted? Class details and static relationships System functionality Object interaction State transition within an object
![Page 13: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/13.jpg)
Some UML Modeling Techniques
Class Diagrams Use Cases/Use Case Diagrams Interaction Diagrams State Diagrams
![Page 14: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/14.jpg)
Example:Class Diagram
Borrower BookcurrBorr bk[]
0..30..1
public class Borrower { Book bk[]; … public Borrower() { bk = new Book[3]; }}
public class Book { Borrower currBorr; …}
![Page 15: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/15.jpg)
Example:Use Case Diagram
Facilitate Checkout
Facilitate Return
Search for Book
LIBRARY SYSTEM
BorrowerLibrarian
![Page 16: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/16.jpg)
Example:Interaction Diagram
CheckoutScreen
:Borrower
:Book
1: checkIfDelinquent()3: borrowBook()
2: checkIfAvailable()
4: setBorrower()
![Page 17: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/17.jpg)
Example:State Diagram (Book)
New
Available
Reserved
Borrowed
start
Librarian activatesbook as available
Borrower returns book
![Page 18: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/18.jpg)
Object-Oriented Design Models
Static Model Class Diagrams
Dynamic Model Use Cases, Interaction Diagrams, State
Diagrams, others
![Page 19: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/19.jpg)
OO Static Model
Classes and Class Diagrams Relationships
Association Aggregation/Composition Inheritance
Dependencies Attribute and Method names
![Page 20: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/20.jpg)
OO Dynamic Model
Goal: Represent Object behavior Object interaction
Traditional/Procedural Dynamic Modeling Data Flow Diagrams (DFDs) Problem: Processes separate from data Need modeling notation that highlight tight
relationship between data & processes
![Page 21: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/21.jpg)
DFD Example(Inventory Management)
Accept and PostDelivery
Item Master
Transaction
Delivery info
![Page 22: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/22.jpg)
OO Counterpart:Object Interaction
Encoder
:Item Master
:Transaction
new (delivery info)
post (item count)
![Page 23: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/23.jpg)
Building anOO Dynamic Model
Identify use cases Describe each use case through an
interaction diagram For more complex objects, provide a state
diagram per class Derive implied methods (and attributes)
![Page 24: OOP Review CS 124. Object-Oriented Programming Revisited Key OOP Concepts Object, Class Instantiation, Constructors Encapsulation Inheritance and Subclasses](https://reader031.vdocuments.site/reader031/viewer/2022031818/56649e425503460f94b34b0f/html5/thumbnails/24.jpg)
What’s Next?
Need to understand the notation Make sure it helps the software development
process When to use the UML techniques
Primarily when specifying OO design Formal means of communication across the
different software development stages