object oriented programmingcourses.daiict.ac.in/.../content/0/oop.pdf · • abstraction strategy...
TRANSCRIPT
Object Oriented Programming
Recall Terms
• Class
• Instance/Object
• Operation
• Method
• Message sending
Class
• It is an Object Type
• Specifies/describes objects of similar behavior
• Is an Implementation construct in OOP languages for creating abstract data types
Object
• Instance of a class
• A run-time instance of a class
• An instance of a class, is an object that belongs to that class
Operation/Method
• Operations that can be performed on objects define behavior of an object
• Class developer needs to provide Implementation of operations
• Java calls them Methods, while C++ calls them member functions
Messages Sending
• In order to get some services of an object, you send them messages
• For, Exampleday.getYear()
books.push( abook );
• day and books are message recipient objects, they would perform some operation in order to serve the client’s request
• Message Sending does not tell, what operation has to be performed in order to serve the request, object determines it – operation binding
What is Object Oriented Programming?
• Different paradigm of Abstraction
– A system is viewed as community of objects contributing toward the goal
• And, there are some more characteristics– Inheritance, and– Polymorphism
Case Study : Banking System
• Suppose you want automate saving account system of a bank-branch.
• Each account, has following information-– Account No, Account Holder Name, Balance
• Following Bank branch operations– Open an account– Locate an account– Deposit money into a account– Withdraw Money From Account– Close an account
Think: How do we program it in C?
• What Data Structure do we use?
• What Functions do we have and what are their prototypes?
Procedure Oriented Programming
• Has been strategy for quiet a log time for major real life applications
• Abstraction Strategy here is : A set of functions (procedures) are going to accomplish the desired task
• Function here may not be exactly function as construct in programming language like C, roughly, function here is a sub-task
• The abstraction strategy is decompose tasks based on functional responsibilities
First Level Data Flow Diagram a formal Diagram: called 0-level DFD
Banking System : DFD Level-1
Implementation in C
Global Data
Do all functions access data that they are supposed to?
Accounts.c
Implementation in C
Accounts.h
main functionbank.c
Some Issue Raised
• Though C module concept, provides some kind of encapsulation by making bank data private within Accounts module- note the use of static keyword with account array– Provides implementation independence, you can
change implementation from static array of accounts to dynamic array or search tree for improving the search
• Still there are some issues– One, what happens when more type of accounts, like
current or loan accounts are added?– Two, how about extending this program to work for
multiple branches, and we provide any-where banking?
Why these issues concerns us
• In addition to complexity, following are concerns these issues address-
• First one relates to reusability and maintainability,
• While second relates to Instantiation
First issue relates to reusability and maintainability
• Issue One: What happens when more type of accounts are added?– Probably you would create another module let us say
CurrentAccount.c, by copy and paste as most of functions remain same
• Similar logic (many business rules are common) has to be coded and maintained at multiple places– a reusability and maintainability issue
Scond issue relates to Instantiation
• Issue Two: how about extending this program to work for multiple branches, and we provide any-where banking?
• Probably you would make the accounts array as two dimensional to store data of multiple branches, in that case, all implementation code has to be changed to access data from different data structure; changing a tested and live program is a nightmare
• A serious concern?• Probably, we would able to find a far better solution if we
could instantiate module account.c, let us call it as branch, and then have an array or list of branchmodule
Solution is not easy in C or procedure oriented approach?
• Things become complex.
• OOP provides, much elegant solution– Community of Objects, that are instances of classes,
given next
• We shall talk about derivation of these classes some time later
OO Solution
Implementation View of Object Oriented Programming
Consider:Bank Class, Branch Class, and Account Class
Implementation ViewProcedure Oriented Programming
Thanks