basic dbms
-
Upload
anuj-singh -
Category
Documents
-
view
227 -
download
0
Transcript of basic dbms
-
8/13/2019 basic dbms
1/42
CS540 Software Design 2Lecture 13
Object-Oriented Programming
Objects can be used effectively to represent real-world entities
For instance, an object might represent aparticular employee in a company
Each employee object handles the processingand data management related to that employee
-
8/13/2019 basic dbms
2/42
3
Objects
An object has:
state - descriptive characteristics
behaviors - what it can do (or what can be done to it)
The state of a bank account includes its account number and itscurrent balance
The behaviors associated with a bank account include the ability
to make deposits and withdrawals
Note that the behavior of an object might change its state
-
8/13/2019 basic dbms
3/42
CS540 Software Design 4Lecture 13
Classes An object is defined by a class
A class is the blueprint of an object
Multiple objects can be created from the same class
-
8/13/2019 basic dbms
4/42
CS540 Software Design 5Lecture 13
Objects and Classes
Bank
Account
A classthe concept)
Johns Bank Account
Balance: $5,257
An objectthe realization)
Bills Bank AccountBalance: $1,245,069
Marys Bank AccountBalance: $16,833
Multiple objectsfrom the same class
-
8/13/2019 basic dbms
5/42
CS540 Software Design 6Lecture 13
Attributes
Contain current state of an object.
Attributes can be classified as simple or complex.
Simple attribute can be a primitive type such as integer,
string, etc., which takes on literal values. Complex attribute can contain collections and/or
references.
Reference attribute represents relationship.
complex object:contains one or more complexattributes
-
8/13/2019 basic dbms
6/42
CS540 Software Design 7Lecture 13
Methods and messages
Method: Defines behavior of an object, as a set of encapsulated functions
Message: Request from one object to another asking second object toexecute one of its methods.
(a)
(b)
(a) Object showing attributes and methods(b) Example of a method
-
8/13/2019 basic dbms
7/42CS540 Software Design 8Lecture 13
Classes
Class: Blueprint for defining a set of similar objects.
Objects in a class are called instances.
-
8/13/2019 basic dbms
8/42
CS540 Software Design 9Lecture 13
Inheritance One class can be used to derive another via inheritance
Classes can be organized into hierarchies
BankAccount
Account
ChargeAccount
SavingsAccount
CheckingAccount
-
8/13/2019 basic dbms
9/42
CS540 Software Design 10Lecture 13
Inheritance (contd)
Inheritance allows one class of objects to be defined as a special case of a more generalclass.
Special cases are subclassesand more general cases are superclasses.
Generalization: process of forming a superclass
Specialization: forming a subclass
Subclass inherits all properties of its superclass andcan define its own uniqueproperties.
Subclass can redefine inherited methods.
All instances of subclass are instances of superclass.Principle of substitutability: instance of subclass can be used whenever method/constructexpects instance of superclass.
A KIND OF (AKO): Name for relationship between subclass and superclass
-
8/13/2019 basic dbms
10/42
CS540 Software Design 11Lecture 13
Types of inheritance
(a)
(b)
(c)
(a) Single(b) Multiple(c) Repeated
(b)
-
8/13/2019 basic dbms
11/42
CS540 Software Design 12Lecture 13
Inheritance (contd) Define humanBeingto be a class
A humanBeinghas attributes, such as age, height,gender
Assign values to attributes when describing object
Define Parent to be a subclassof HumanBeing
A Parent has all attributes of a HumanBeing, plusattributes of his/her own (name of oldest child,number of children)
AParentinherits all attributes of humanBeing The property of inheritance is an essential feature of
object-oriented languages such as Smalltalk, C++, Ada95, Java (but not C, FORTRAN)
-
8/13/2019 basic dbms
12/42
CS540 Software Design 13Lecture 13
Inheritance (contd)
UML notation
Inheritance is represented by a large open triangle
-
8/13/2019 basic dbms
13/42
CS540 Software Design 14Lecture 13
Java implementation
-
8/13/2019 basic dbms
14/42
CS540 Software Design 15Lecture 13
Overriding and OverloadingOverriding: Process of redefining a property within a subclass.
Overloading:Allows name of a method to be reused with a class or acrossclasses.
Overriding Example:
Might define method in Staff class to increment salary based on commissionmethod void giveCommission(float branchProfit) {
salary = salary + 0.02 * branchProfit; }
May wish to perform different calculation for commission in Manager subclass:
method void giveCommission(float branchProfit) {
salary = salary + 0.05 * branchProfit; }
-
8/13/2019 basic dbms
15/42
CS540 Software Design 16Lecture 13
Aggregation
UML Notation
-
8/13/2019 basic dbms
16/42
CS540 Software Design 17Lecture 13
Association
UML Notation
-
8/13/2019 basic dbms
17/42
CS540 Software Design 18Lecture 13
Equivalence of Data and Action
Classical paradigm record_1.field_2
Object-oriented paradigm thisObject.attributeB
thisObject.methodC()
-
8/13/2019 basic dbms
18/42
CS540 Software Design 19Lecture 13
ExampleChapter 7 Schach (2002)
Design of an operating system for a large mainframecomputer. It has been decided that batch jobs submittedto the computer will be classified as high priority,medium priority, or low priority. There must be three
queues for incoming batch jobs, one for each job type.When a job is submitted by a user, the job is added tothe appropriate queue, and when the operating systemdecides that a job is ready to be run, it is removed from
its queue and memory is allocated to it Design 1 (Next slide)
Low cohesionoperations on job queues are spread all overproduct
-
8/13/2019 basic dbms
19/42
CS540 Software Design 20Lecture 13
Data EncapsulationDesign 1
-
8/13/2019 basic dbms
20/42
CS540 Software Design 21Lecture 13
Data EncapsulationDesign 2
-
8/13/2019 basic dbms
21/42
CS540 Software Design 22Lecture 13
Data Encapsulation
m_encapsulationhas informational cohesion
m_encapsulation is an implementation of dataencapsulation
Data structure (job_queue) together with operationsperformed on that data structure
Advantages
Development
Maintenance
-
8/13/2019 basic dbms
22/42
CS540 Software Design 23Lecture 13
Data Encapsulation and
Development Data encapsulation is an example of abstraction Job queue example
Data structure job_queue
Three new functions initialize_job_queue add_job_to_queue delete_job_from_queue
Abstraction Conceptualize problem at higher level
job queues and operations on job queues
not lower level records or arrays
-
8/13/2019 basic dbms
23/42
CS540 Software Design 24Lecture 13
Stepwise Refinement
Step 1: Design in terms of high level conceptsIt is irrelevant how job queues are implemented
Step 2: Design low level components
Totally ignore what use will be made of them
In 1st step, assume existence of lower level Concern is the behavior of the data structure
job_queue
In 2nd step, ignore existence of high level
Concern is the implementation of that behavior
In a larger product, there will be many levels of abstraction
-
8/13/2019 basic dbms
24/42
CS540 Software Design 25Lecture 13
Data Encapsulation and
Maintenance
Identify aspects of product likely to change
Design product so as to minimize the effectsof change
Data structures are unlikely to change
Implementation may change
Data encapsulation provides a way to copewith change
I l i f Cl J bQ
-
8/13/2019 basic dbms
25/42
CS540 Software Design 26Lecture 13
Implementation of ClassJobQueue
C++
-
8/13/2019 basic dbms
26/42
CS540 Software Design 27Lecture 13
Implementation of queueHandler
C++ Java
-
8/13/2019 basic dbms
27/42
CS540 Software Design 28Lecture 13
Data Encapsulation and
Maintenance (contd)
What happens if queue is now implemented as a two-way linkedlist ofJobRecord?
Module that usesJobRecordneed not be changed at all,merely recompiled
C++
Java
-
8/13/2019 basic dbms
28/42
CS540 Software Design 29Lecture 13
Abstract Data Types
Problem with both implementations
Only one queue
Need
We need:
Data type+ operations performed on instantiationsof that data type
Abstract data type
T d
-
8/13/2019 basic dbms
29/42
CS540 Software Design 30Lecture 13
Abstract Data Type (contd)
(Problems caused bypublicattributes solved later)
-
8/13/2019 basic dbms
30/42
CS540 Software Design 31Lecture 13
Information Hiding
Data abstraction
Designer thinks at level of an ADT
Procedural abstraction
Define a procedureextend the language
Instances of a more general design concept, information hiding
Design the modules in way that items likely to change arehidden
Future change is localized
Changes cannot affect other modules
I f ti Hidi ( td)
-
8/13/2019 basic dbms
31/42
CS540 Software Design 32Lecture 13
Information Hiding (contd)
C++ abstract
data typeimplementationwith information
hiding
-
8/13/2019 basic dbms
32/42
CS540 Software Design 33Lecture 13
Information Hiding (contd)
Effect of information hiding viaprivateattributes
-
8/13/2019 basic dbms
33/42
CS540 Software Design 34Lecture 13
Polymorphism and Dynamic
Binding
Classical paradigm Must explicitly invoke correct version
Polymorphism and Dynamic Binding
-
8/13/2019 basic dbms
34/42
CS540 Software Design 35Lecture 13
Polymorphism and Dynamic Binding(contd)
Object-oriented paradigm
-
8/13/2019 basic dbms
35/42
CS540 Software Design 36Lecture 13
Polymorphism and Dynamic
Binding (contd)All that is needed is myFile.open()
Correct method invoked at run-time (dynamically)
Method opencan be applied to objects ofdifferent classes
Polymorphic
-
8/13/2019 basic dbms
36/42
CS540 Software Design 37Lecture 13
Polymorphism and dynamic binding
(contd)
MethodcheckOrder (b : Base)can be applied to objects of any subclass
ofBase
-
8/13/2019 basic dbms
37/42
CS540 Software Design 38Lecture 13
Polymorphism and Dynamic
Binding (contd)
Can have a negative impact on maintenance Code is hard to understand if there are multiple
possibilities for a specific method
Polymorphism and dynamic binding Strength and weakness of the object-oriented paradigm
Polymorphism and dynamic binding
-
8/13/2019 basic dbms
38/42
CS540 Software Design 39Lecture 13
Polymorphism and dynamic binding
(contd)
Polymorphism: Means many forms.
Dynamic Binding:Runtime process of selecting appropriate method based onan objects type.
Example:With list consisting of an arbitrary no. of objects from the Staff hierarchy,we can write: list[i]. print
and runtime system will determine which print() method to invoke depending onthe objects (sub)type.
-
8/13/2019 basic dbms
39/42
CS540 Software Design 40Lecture 13
Cohesion and Coupling of Objects
No such thing! Object-oriented cohesion and coupling always reduces to
classical cohesion
The only feature unique to the object-oriented paradigm is
inheritance Cohesion has nothing to do with inheritance
Two objects with the same functionality have the samecohesion
It does not matter if this functionality is inherited or not Similarly, so-called object-oriented coupling always reduces to
classical coupling
-
8/13/2019 basic dbms
40/42
CS540 Software Design 41Lecture 13
Object-Oriented Metrics (contd)
Two types of so-called object-oriented metric Not related to inheritance
Reduces to a classical metric
Inheritance-related May reduce to a classical metric
No problem Classical metrics work just fine
But dont mislead others by calling them object-oriented
-
8/13/2019 basic dbms
41/42
CS540 Software Design 42Lecture 13
Advantages of Objects
Same as as advantages of abstract data types
Information hiding
Data abstraction
Procedural abstraction
Inheritance provides further data abstraction
Easier and less error-prone productdevelopment
Easier maintenance
Objects are more reusable than modules withfunctional cohesion
-
8/13/2019 basic dbms
42/42
Summary