a. Inheritance b. Abstraction 1. Explain the following OOPS concepts with an example - PDF

Please download to get full document.

View again

of 5
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report



Views: 37 | Pages: 5

Extension: PDF | Download: 0

Related documents
1. Explain the following OOPS concepts with an example a. Inheritance It is the ability to create new classes that contain all the methods and properties of a parent class and additional methods and properties.
1. Explain the following OOPS concepts with an example a. Inheritance It is the ability to create new classes that contain all the methods and properties of a parent class and additional methods and properties. If class Y is derived from class X, Y is the child and X is the parent or base class. A class without a parent is called root class. A class without a child class is called a leaf node. Inheritance is one of the most crucial concepts in object-oriented programming, and it has a direct effect on how you design and write classes. Inheritance is a powerful mechanism that allows a class to inherit functionality from an existing class. To create the new class, you only have to specify how that class is different from an existing class, and inheritance gives you automatic access to the existing class. With inheritance, all classes-those you write, those from other class libraries that you use, and those from the standard utility classes as well-are arranged in a strict hierarchy Each class has a superclass (the class above it in the hierarchy)-except for the topmost class in the hierarchy. Each class can have one or more subclasses (classes below it in the hierarchy). Classes in the hierarchy inherit from classes above them in the hierarchy. Subclasses inherit all the methods and variables from their superclasses. In practical terms, this means that if the superclass defines behavior your class needs, you don't have to redefine that behavior or copy that code from some other class. Your class automatically receives that behavior from its superclass, the superclass gets behavior from its superclass, and so on, all the way up the hierarchy. Your class becomes a combination of all the features of the classes above it in the hierarchy, as well as its own features. Ex: A class car inherited from base class vehicle will have all the methods and properties of vehicle class along with its own methods and properties. b. Abstraction The process of picking out or abstracting common features of objects and procedures. It is closely related to two other important techniques, encapsulation and information hiding. Abstraction is the process of combining multiple smaller operations into a single unit that can be referred to by name. It is a technique to factor out details and ease use of code and data. It is by analogy with abstraction Abstraction in mathematics is the process of extracting the underlying essence of a mathematical concept, removing any dependence on real world objects with which it might originally have been connected, and generalising it so that it has wider applications. Ex: Two addition functions used to perform addition of float and integer values can be abstracted to one add function. This technique reduces complexity. c. Encapsulation The process of combining elements to create a new entity is called encapsulation. The localization of knowledge within a module. Because objects encapsulate data and implementation, the user of an object can view the object as a black box that provides services. Instance variables and methods can be added, deleted, or changed, but if the services provided by the object remain the same, code that uses the object can continue to use it without being rewritten. Ex: A procedure is a type of encapsulation because it combines series of computer instructions. Also a complex datatype such as a class or record relies on encapsulation. It is used to create high level objects. This is closely related to abstraction and information hiding. d. Polymorphism It is the ability to process objects differently depending on their data type or class. Moreover it is ability to redefine methods for derived classes Ex. Given a base class Vehicle, polymorphism enables the programmer to define different design specification for any number of derived classes such as Truck, Car, Bus etc. No matter what the type of vehicle is being referred, to applying the design specification method to it, will return correct results 2. A college library is maintained for students. The students issue books from the library and also take books for reference(reference books are not issued). A student can be issued a book only after membership. Other activities of the library include maintaining stock of books, renewing subscriptions of magazines and periodicals whenever the subscriptions expire, taking old and damaged books out of circulation and put them up for sale, ordering new books as and when required and collecting fine from the students for loss /damage or late return of books. Based on this data model a software system for automation of this process You are supposed to do the following. a. Specify the scope of your system. b. Prepare use cases and list out their scenarios ( also include a use case description). c. Prepare class diagrams. Ans : (a) The scope of the system for the student would be as follows: (1) Issue books/periodicals/magazines. (2) Be a member. (3) Reference books. The scope for the librarian would be as follows: (1) Issue and return of books. (2) Grant membership. (3) Stock verification at the year end. (4) Renew/terminate subscriptions. (5) Place orders for books. (6) Remove old books out of circulation and put them up for sale. (7) Collect fine from student on late return, loss or damage to books. (b) Use case and scenario Precondition Library staff and student validated to Library Management System Library DataBase initialized Main flow of events Enter book Determine due date Exceptional flow of events Student has over due books Book number not valid Postcondition Student DB entry updated to reflect new resource Book DB entry updated to reflect changed status: checked out Due date assigned to the book DB entry Use case description (Scenario) (1) membership: (a) Student applies for membership to an library. (b) Librarian processes the various applications and grants membership. (2) books: (a) The student issues a book after selection. (b) The librarian grants the issue of book after record entry. (c) The student returns the book. (d) The librarian accepts the book and makes a record entry (3) fine: (a) The student pays a declared amount of fine in case of loss/damage or late return of books. (b) The librarian accepts the fine after issuing a receipt. (4) stock verification: (a) The librarian perform a stock verification at the year end. (b) He/she takes old books out of circulation and puts up for sale. (c) Renews/terminates subscription of periodicals/magazines. (5) order new books: (a) order new books as and when required any time of the year. (6) Reference Books (a) Students Refers to the reference books (c) Class diagram Library Management System USE CASE LIBRARY MANAGEMENT SYSTEM Applies for MEMBERSHIP References Reference Books Grants Student Issue/return Pays BOOKS FINE Issue/Takes back collects LATE FEES DAMAGE LOSS STOCK VERIFICATION does librarian extends OLD BOOKS SALE extends RENEW SUBSCRIPTION Places order supplies ORDER NEW BOOKS Book publisher s
View more...
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks