Download presentation
Presentation is loading. Please wait.
Published byHomer Wilkins Modified over 8 years ago
1
Ch 7: From Modules to Objects (Part Two) CSCI 4320
2
Data Encapsulation A data structure together with the operations performed on that data Abstraction: gathering into one unit of all aspects of the entity modeled by that unit Stepwise refinement –Designer can develop data structure and the operations performed on it and later be concerned with how the data structure will be implemented
3
Data Encapsulation Maintenance –Product is designed to minimize the effects of future changes –Having related procedures and data together helps allow programmers to cope with change.
4
Abstract Data Type A data type together with the operations to be performed on instantiations of that data type Example of Data Encapsulation Class
5
Information Hiding Structuring the design so that the resulting implementation details are hidden from the other modules.
6
Inheritance, Polymorphism and Dynamic Binding Extending a class so that a new class is created while at the same time retaining the basic characteristics of the original Base Class (Super Class) –Contains common attributes and functions Derived Class (Subclass) –Not only has capabilities of the original, but also takes on new attributes and processes of its own
7
Classical Paradigm vs Object Oriented Classical different named operations –OpenDiskFile –OpenTapeFile –OpenDiskFile Object Oriented –Open –Super Class: FileClass Contains abstract method header. –Sub Classes: DiskFileClass, TapeFileClass and DisketteFileClass Each class has an method named open
8
Polymorphism and Dynamic Binding Having an abstract method in a parent (super class) forces the children (sub classes) to create a method with that name –Results in simple call statement myfile.open(); Dynamic Binding –Determine at run-time which method is called.
9
Inheritance Goal of Inheritance –Create a new subclass that differs from its parent class without affecting the parent Problems of Inheritance –Fragile Base Class: Changes result in Ripple Effect Any change to an existing class directly affects all descendents At the very least, all affected units must be recompiled –Creating subclasses that should not inherit all attributes of the parent Objects lower in the hierarchy can quickly get large, with resulting storage problem
10
Polymorphism and Dynamic Binding Difficult to detect error –It is generally not possible at compile time to detect which polymorphic method will be invoked at runtime Negative impact on maintenance –Developer not the same as maintainer –Programmer must consider all possible methods that could be invoked dynamically at a specific place in the code.
11
Reasons for Success of Object- Oriented Paradigm Overall equal attention to data an operations A well-designed object (high cohesion, low coupling) models all the aspects of one physical entity Implementation details are hidden
12
Weakness of Object-Oriented Design Development effort and size can be large The first object-oriented project can be larger than expected. –Especially if there is a GUI However, some classes can frequently be reused in the next project –Especially if there is a GUI
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.