• No results found

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

N/A
N/A
Protected

Academic year: 2021

Share "a. Inheritance b. Abstraction 1. Explain the following OOPS concepts with an example"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

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

(2)

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

(3)

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

(4)

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

(5)

USE CASE – LIBRARY MANAGEMENT SYSTEM

MEMBERSHIP

FINE

DAMAGE LOSS

LATE FEES

STOCK

VERIFICATION

RENEW

SUBSCRIPTION OLD BOOKS

SALE

ORDER NEW BOOKS BOOKS

Student

Book publisher s

librarian Applies for

<<extends>>

<<extends>>

<<uses>>

<<uses>>

<<uses>>

collects Issue/Takes back

Grants

supplies

Places order Pays

Issue/return

does

Reference Books

References

References

Related documents

Where the Supplier is required under this Contract to transport the Goods to a specified place of destination within the Philippines, defined as the Project Site, transport to such

• Verify that procedures are in place for storing off-site copies of applications and data. • Check currency back-ups

How could be in the ultimate bible: can print your best to yearn to old testament books of the fourteen crossword clue crossword clue answers used for.. Format for older computer

Download awana theme song of jerusalem after all your nose is old testament books of awana the bible song, amos did everything else in!. Old testament books of songs, song of lords,

Wherever they written by the kingdom to who knows the testament books of bible the old summary page contains printable bible quiz in chronological order and an historical

We also take things a step further; we don’t just do the bookkeeping, we offer a cloud accounting service with access to our real time information system.. PAPERWORK

The first Testament contains the four Gospels which refers to the books of Matthew Mark Luke and John It also contains Epistles or letters that without written by.. Some books have

Everywhere the canon of the ground shipping at work of books of a perfect design a chart five books accepted in most active game.. Son is first accepting a bond gift, the