You are on page 1of 22

Dept.

of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

II B.Tech II Semester
Handbook
Object Oriented Programming

SUB:OOP
Branch: II CSE II SEM
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Unit-I:
Object oriented thinking: Need for oop paradigm, A way of viewing world
Agents, responsibility, messages, methods, classes and instances, class
hierarchies(Inheritance), method binding, overriding and exceptions, summary of
OOP concepts, copying with complexity, abstraction mechanism.
Objectives:
To learn about how the Object Oriented approach can be used for solving a
particular task
To understand how the OOP concepts reduces the program complexity by crating
objects and calling the methods when they are needed.
Lecture Plan:
S.No.
1
2
3
4
5.
6.

Name Of The Topic


Need for oop paradigm
Classes, instances and
hierarchies
Inheritance
OOPs concepts
Coping with complexity
Total Classes

No Of Classes
01
01

Date

Remarks

01
01
01
05

Important Questions:
1) What are the OOPs features. Explain the importance of OOP languages?
2) What are the applications of oops?
4) What is data abstraction and encapsulation?
5) Explain about inheritance and polymorphism with an example?
6) Compare Procedural and OOP Languages?
7) What is a class inheritance hierarchy? How is it linked to classes and behavior?
8) Write a short notes on:
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
9) Explain the importance of Object-oriented programming languages.
10)Differentiate runtime and compile time polymorphism.
Applications:
To differentiate the different styles of programming
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

To learn the importance of oop


Assignment Questions:
1)Explain The importance of OOPs concept?
2)what are the OOPs features of?
3)OOPs applications ?
Student is expected to learn:
ToLearn about classes and inheritance hierarchy
Unit-II:
Java Basics: History of Java, Java Buzzwords, data types, variables, scope and life
time of variables, arrays,
operators, expressions, control statements, type conversion and casting, simple java
program, concepts of
classes, objects, constructors, methods, access control, this keyword, garbage
collection, overloading methods
and constructors, parameter passing, recursion, nested and inner classes, exploring
string class.
Objectives:
The major objectives of this unit are:
1)To introduce java datatypes,control statements,
2) To Introduce Simple java programs and about constructors
3) To make understand the different parameter passing technics
Lecture Plan:
S.No
1
2
3
4.
5.
6.
7.

Name Of The Topic


History of java
Data types, Variables & their
scope
Expression &control statements
Concepts of classes
Constructors, Access control
Garbage Collection, Method
overloading
Nested and inner classes
Total Classes

Handbook II CSE II SEM

No Of Classes
02
02
02
02
02
03
02
15

Date

Remarks

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

1) Explain about buzzwords of java?


2) What are the data types used in java? Give examples?
3) Explain about control statements in java?
4) What is type casting and conversion? When it is required?
5) Explain the general syntax of writing an application in java. Also explain the
steps to run the application
of java program?
6) What is an array? How arrays are declared in java with an example?
7) Explain operator precedence in java?
8) Write a java program for multiplication of matrices?
9) What is a constructor? What are its special properties?
10) Explain about class and object?
11) Explain about method overloading with example?
12) Explain about constructor overloading with example?
13) Write a java program for finding factorial of a given no.?
14) Explain about parameter passing technique?
15) Write a program to compute
1/1+1/2+1/3+--------+1/n
1/2^0+1/2^1+1/2^2+------+1/2^n
16) Explain the use of static, final, public, and private keywords?
Applications:
To write java programs with the help of control statements
Message pasing by the help of parameters
Assignment Questions:
1) Explain the use of static, final, public, and private keywords?
2) Explain about method overloading with example
3) What are the data types used in java? Give examples?
4) What is type casting and conversion? When it is required?
Student is expected to learn:
To learn about the control structures
Parameter passing technics

UNIT-III:
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Inheritance: Hierarchical abstractions, Base class object, subclass, subtype,


substitutability, forms of
inheritance- specialization, specification, construction, extension, limitation,
combination, benefits of
inheritance, costs of inheritance. Member access rules, super uses, using final with
inheritance, Polymorphism method
overriding, abstract classes, the object class
Objectives:
The major objectives of this unit are:
To have an indepth knowledge of inheritance
Usage of final and super keywords
Lecture Plan:
S.No
1
2
3
4.
5.
6.

Name Of The Topic


Basics of inheritance.
Forms of inheritance.
Member access rules.
Final & super keyword uses
Polymorphism
Method
overriding,
Abstract
classes and object class
Total Classes

No Of Classes
01
01
01
02
02
02

Date

Remarks

09

Important Questions:
1) Discuss about Hybrid inheritance with an example?
2) Discuss about hierarchical inheritance with an example?
3) Explain about abstract class with an example?
4) Explain about the usage of super keyword with an example?
5) What is method overriding? How methods overriding is achieved in Java, with
an example?
6) What happens when the final keyword is used for inheritance? Explain with an
example?
7) Explain about benefits of inheritance. Define inheritance write a java program
for simple inheritance
8) What is an abstract class? Can an abstract class have constructor? Explain?
9) Explain final keyword with all its usages. Support explanation with a program.
10)What is inheritance? How is it different from Aggregation?
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Applications:
Reusing the classes with the help of inheritance
How to add new things to the existing class
Assignment Questions:
Explain about benefits of inheritance. Define inheritance write a java program for
simple inheritance
What happens when the final keyword is used for inheritance? Explain with an
example?
Student is expected to learn:
Learn about inheritance and usage of different keywords
UNIT-IV:
Packages and Interfaces: Defining, Creating and Accessing a Package,
Understanding CLASSPATH,
importing packages, differences between classes and interfaces, defining an
interface, implementing interface,
applying interfaces, variables in interface and extending interfaces. Exploring
java.io.
Objectives:
The major objectives of this unit are:
The importance of packages classes and interfaces
Lecture Plan
S.No Name Of The Topic
1
2

Package basics
Difference between classes and
interface

3
4.

Interface basics
Exploring java.io package
Total Classes

Important Questions:
Handbook II CSE II SEM

No Of
Classes
01
02
02
01
06

Date

Remarks

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

1) Prove that all the methods in interface are public. Explain with an example?
2) What is package? Explain the procedure to create package with an example?
3) List the advantages of packages and interfaces?
4) What is the usage of import statement? Explain with an example?
5) Explain how interfaces are implemented with an example?
6) Explain in detail the process of defining, creating, importing and accessing a
package with example?
7) How interfaces can be extended? Explain with an example?
8) Give difference between abstract class and interface?
9) How multiple inheritances are achieved in java with the interfaces? Explain with
an example?
10)Differentiate between Packages and Interfaces? Explain different types of java
packages?
Applications:
To make the data more abstract through the use of packages
Assignment Questions:
1) Difference between interface and classes
2) Creating and accessing a package
Student is expected to learn:
To create packages and interfaces
UNIT-V:
Exception Handling: Concepts of exception handling, benefits of exception
handling, Termination or
resumptive models, exception hierarchy, usage of try, catch, throw, throws, finally,
built in exceptions, creating
own exception sub classes.
String handling, Exploring java.util.
Objectives:
The major objectives of this unit are:
To know what are exceptions and how they are handled
Lecture Plan:
S.No Name Of The Topic
Handbook II CSE II SEM

No Of Classes

Date

Remarks

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

1
2
3

Exception handling
Exception handling using keywords
Creating
own exception sub classes.

02
02
02

4.

Exploring java.util.
Total Classes

01
07

Important Questions:
1) When you use nested try statements. Explain nested try statements with the help
of an example?
2) Explain the following:
try, catch, throw, throws, finally
3) What are the checked Exceptions and Unchecked Exceptions? Explain some of
these exceptions with
an example and also give the difference between them.
4) In JAVA, is exception handling implicit or explicit or both. Explain with the help
of example java
programs.
5) Explain about different types of exception handling techniques in java program.
6) a) Write a java program to demonstrate exception chaining.
b) Can we catch the exception without catch block? Explain?
7) How user can create user defined exceptions. Explain with an example?
8) Explain Logging in Java with all its levels.
9) What is Collection in Java? Can you identify any real life example which is
similar to a collection in
Java?
10) Explain the difference between: i) Vector and ArrayList. ii) Enumeration and
Iterator.
11)What are the Generics and how are they used in Java with an example?
12) Explain the related objects provided in java.util package?
13)What are the string handlings functions? Explain?
Applications:
How the exceptional situations is handled through java programs
How to use different classes in java
Assignment Questions:
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

1) What are the checked Exceptions and Unchecked Exceptions? Explain some of
these exceptions with
an example and also give the difference between them.
2) Explain the following:
try, catch, throw, throws, finally
3)What are the string handlings functions? Explain?
4) Explain about different types of exception handling techniques in java program.
Student is expected to learn:
To learn how to handle the exceptions
UNIT-VI:
Multithreading: Differences between multi threading and multitasking, thread life
cycle, creating
threads, thread priorities, synchronizing threads, inter thread communication,
thread groups, daemon
threads. Enumerations, autoboxing, annotations, generics.
Objectives:
The major objectives of this unit are:
Difference between multiprocessing and multithreading
Inter thread communication
Impotant Questions
1) What is multithreading? Give an example for creation of multiple threads?
2) Compare thread based and process based multitasking?
3) Explain the creation of threads with an example?
4) What is the difference between suspending and stopping a thread? List the
methods used to block a
thread?
5) Can we catch the exception without catch block? Explain?
6) Explain how synchronization can be obtained in threads with example?
7) What is deadlock? How it can be avoided. Explain?
8) How user can create user defined exceptions. Explain with an example?
9) How the priorities can be assigned to threads? Explain with example?
10)Define each of the following terms.
a) Thread b) Multithreading
c) Waiting state and Timed_waiting state d) Running state
e) Preemptive scheduling f) Runnable interface
Handbook II CSE II SEM

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

g) Monitor h) Notify method


i) Join() method.

Applications:
To Create multithreaded progamming

Handbook II CSE II SEM

10

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

S.N Name Of The Topic


o
1
Multi Threading
2
Creating threads,Thread
lifecycle
3.
Thread synchronization&inter
thread communication
4.
Enumerations,auto boxing
Total Classes
Assignment Questions:

No
Of Date
Classes
01
01

Remakes

02
01
05

1) What is deadlock? How it can be avoided. Explain?


2) Explain the creation of threads with an example?
Student is expected to learn:
How to create multi threaded programs
UNIT-VII:
Event Handling: Events, Events sources, Event classes, Event Listeners,
Delegation event model, handling
mouse and keyboard events, Adapter classes.
The AWT class hierarchy, user interface components- labels, button, canavas,
scrollbars, text components,
check box, check box group, choices, lists panels- scroll pane, dialogs, menu bar,
graphics, layout managerlayout
manager types- border, grid, flow, card and grid bag.
Objectives:
The major objectives of this unit are:
To make understand how events are handled.

Lecture Plan:
S.No
1

Name Of The Topic


Event handling

Handbook II CSE II SEM

11

No Of Classes
01

Date

remarks

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

2
3
4.

Event handling though


mouse,keyboard
AWT hierarchy,user interface
components.
Lists panel

02

Total Classes

08

03
02

Important Questions
1) Give overview of java event handling mechanism?
2) What is event source? Give examples of event sources. How events are
generated. All Events are
generated by user actions. Explain?
3) What are the methods supported by the following interfaces explain.
a) Action Listener Interface
b) Mouse Motion Listener Interface
c) Text listener Interface
4) Define event. Give examples of events. Define event handler. How it handles
events?
5) What are delegation event modes? Explain it what are the benefits?
6) With an example show the handling of mouse events in java?
7) With an example show the handling of key events in java?
8) How is a container difference from other types of components?
9) What is a window? What are the operations of window?
10) Explain about the following things: font, Graphics, Color?
11)What are various layout managers available in JFC? Explain of them with their
Functionality. Explain
with example?
12)How you will add text area, button, checkbox, lists to an applet? Explain with
skeleton Code?
13)Write short notes on
a) Jscrollpane
b) Jtabbedpane
c) JToolbar
Applications
To create GUI
To handle events
Handbook II CSE II SEM

12

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Assignment Questions:
1)Give overview of java event handling mechanism?
2)Define event. Give examples of events. Define event handler. How it handles
events?
Student is expected to learn:
How to handle the events
To create graphics
UNIT VIII:
Applets: Concepts of Applets, difference between applets and applications, life
cycle of an applet, types of
applet, types of applets, creating applets. Passing parameters to applets.
Swing: Introduction, limitations of AWT, MVC architecture, components,
containers, exploring swingJApplet, JFrame and JComponent, Icons and Labels, text fields, buttons- The
JButton class, Check boxes, Radio
buttons, Combo boxes, Tabbed Panes, Scroll Panes, Trees, and Tables
Objectives:
The major objectives of this unit are:
To learn about applets and swings
.
Lecture Plan:
S.No
1
2
3
4
5.

Name Of The Topic


Applets, Life Cycle of
applets and Applet creation
Passing parameters, Swing
Introduction

No Of Classes
02

MVC
Architecture,components
Swing jApplet,jframe
Jbutton classes
Total Classes

Important Questions
1) a) What are the advantages of Layout
2) Explain the life cycle of an applet?
Handbook II CSE II SEM

13

02
02
01
02
09

Date

remarks

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

3) Describe the arguments used in the method drawRoundRect()?


4) How parameters can be passed to applet?
5) How Jtable is created with a simple example?
6) Explain about layout manager? With an example?
7) Explain the creation of Jtree with an example?
8) Explain the difference between Swing and AWT.
9) What is the difference JButton and JToggleButton
10)What are the various dialog boxes available in Swing and how are they created?
Applications
To create applets
To create GUI
Assignment Questions:
1) Explain the life cycle of an applet?
2) Explain the difference between Swing and AWT.
3) What are the various dialog boxes available in Swing and how are they
created?
4) What are the advantages of Layout
Student is expected to learn:
To create GUI with different controls

OOP Case Study:


Handbook II CSE II SEM

14

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

The Bank Account Class


Summary
The example of a bank account class is a canonical one in the object oriented
programming (OOP) literature. Here are my thoughts on how the bank
account problem should be approached.
The object-oriented bank account example is a common demonstration of
OOP by attempting to model a bank account class.Eric Theriault referenced
a talk on his blog by Kevlin Henney which brought the old chestnut to the
forefront of my consciousness again. Here is the quote from Eric's blog which
I find rather enlightened.
... one of my courses at OOPSLA has been with Kevlin Henney, and he
reminds us that when developing object oriented software, the getters and
setters are generally not the proper abstraction for an object. More specifically,
his example was for a Bank Account, where the methods provided are
getBalance() and setBalance(). While this is a very powerful interface, this is
not the proper abstraction to use, especially since in this case, the object
could change state between the initial get and the final set. As such, a better
interface would be a method to acquire the current balance, a method to
withdraw funds, and a method to deposit funds. In addition to being a more
coherent interface, the business logic can easily be applied in this design.
There is no argument from me that Get and Set is a naive interface to a multithreaded bank account class. It is pretty safe to expect that a bank account
class is going to be multi-threaded, as most models of a transactional system
probably should be.
The issue is, if we only provided locksafe Deposit / Withdraw, how do we deal
with something like deposit interest? We could conceivably provide another
function for DepositInterest. The next problem would be a bank fee scheme
which depends on the amount of money in the account. Again this also has to
be thread safe. But what happens is we are overloading the repsonsibility of
the account class.
What makes the most sense is to keep the BankAccount class as simple as
possible. Something like: ViewBalance, GetBalanceAndLock,
SetBalanceAndUnlock. Strictly speaking nothing else is needed, all other
Handbook II CSE II SEM

15

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

functionality can be provided from that basis. More sophisticated functionality


can be implemented in very simple account accessor classes. Withdraw and
Deposit for instance chould be separated into a new class which could be
descirbed as below:
TellerAccountAccessor {
PayBill(amount) {
cur = account.GetBalanceAndLock()
account.SetBalanceAndUnlock(cur - amount);
}
Withdraw(amount) {
cur = account.GetBalanceAndLock()
account.SetBalanceAndUnlock(cur - amount);
}
Deposit(amount) {
cur = account.GetBalanceAndLock()
account.SetBalanceAndUnlock(cur + amount);
}
BankAccount account;
}

Since I brought up the concerns of interest and fees it would make sense to
have another class which provides that functionality:
BankAccountAccessor {
DeductFees(exemption, fees) {
cur = account.GetBalanceAndLock();
if (cur < exemption) {
cur = cur - fees;
}
SetBalanceAndUnlock(cur);
}
DepositInterest(interest_rate) {
cur = account.GetBalanceAndLock();
interest = cur * interest_rate;
cur = cur + interest;
SetBalanceAndUnlock(cur);
}
BankAccount account;
}

I invite the reader to share their thoughts on the subject. Even the simplest of
basic object oriented designs can make for interesting and informative
discussion.

Handbook II CSE II SEM

16

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

OOP Case Study: The Bank Account Class


(Part 2)
by Christopher Diggins
November 16, 2004

Summary
My previous blog entry on the bank account class, sparked some lively and
interesting discussion. It also revealed two very distinct approach to object
oriented programming, which I label the bottom-up approach and the topdown approach.
I have identified two very distinct approaches to object oriented programming,
which I label the bottom-up approach and the top-down approach. I will
revisit the bank account examples from an earlier post OOP Case Study:
The Bank Account Class, while attempting to explain the different techniques
and to show how they compliment each other.
The original problem was stated as:
represent a bank account class in code
There are two ways to interpret this, as simply as possible or as realistically as
possible. Each interpretation embodies a separate design approach, which
are I hope to show, compatible with each other .

The Top-Down Approach


Since the bank account example lacks sufficient contextual information we
can fill in the blanks use some basic assumptions we know about bank
accounts in financial institutions:
any modification to the account should done in a thread-safe manner
any modifcation to the account should be recorded as a transaction

the balance should be accesible at any given date or time

The following is an example high-level representation of what an account


could be which satisfies the above requirements:
class Account {
ApplyTransaction(Transaction);
TransactionHistory GetTransactionHistory();
GetBalanceAsOf(Date);

Handbook II CSE II SEM

17

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions
}

Following the top-down approach, we would then continue by specifying the


sub-elements (i.e. Transaction and TransactionHistory) and fill in the
implementation details.

The Bottom-Up Approach


The other approach, is that we instead try to construct a class which is as
general as possible, but is still useful. Making as few assumptions about the
bank account as possible, one specification could be:
it has a balance which can be viewed and modified
In the absence of further information, it can be argued that the simplest thing
that can possibly work (TSTTCPW) is the correct answer, so I propose:
int balance;
Nothing is much simpler than an int! The bottom-up approach would be to
then specify more sophisticated classes that are composed-of or inheritedfrom the low-level classes as more specifications are included. For instance
consider the new specification:
account viewing and updating must be possible in a thread safe manner
class Account {
Lock();
Unlock();
int GetBalance();
SetBalance(int);
fields
int balance;
}

This is arguably the simplest class which satisfies the previous requirements,
and reuses the previous definition. Introducing yet another requirement:
any modifcation to the account should be recorded as a transaction
would imply a transactional account:
class TransactionalAccount {
int GetBalance();
ApplyTransaction(Transaction);
fields
Account account;
}

By now I think it should be obvious where I am going with this. Starting at the
bottom and introducing new layers of abstraction I can eventually reach the
same design as was proposed by the top-down approach.
Handbook II CSE II SEM

18

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Summary: Combining the Two Approaches


The the top-down approach, which is more common, is to start with the full set
of specifications, design an interface, and then provide the implementation
afterwards. The danger of this approach is that it often doesn't go deep
enough into the so-called "implementation details". This can lead to designs
that are too brittle because the objects are overloaded with responsibility and
concerns aren't properly delegated into separate classes. OOP is useful at
lower levels of abstraction including implementation details. The other big
danger of the top-down approach is that we can make premature assumptions
about a system, based on the language used to describe it.
The bottom-up approach implies starting with classes which represent the
system as generally as possible and then using them to build more
sophisticated and precise classes which eventually satisfy the problem. A
bottom-up approach has its own pitfalls of course, such as the fact that it can
be tempting to try and fit high-level classes to correspond with the limitations
of the low-level classes, and the fact that programmers sometimes don't
implement solutions with the appropriate level of abstraction.
Clearly both the top-down and bottom-up approaches have their value and
place in software development. It is important in any discussion of OOP
techniques to be aware of both approaches, as they each can give useful and
important insights into the design and implementation of software, which are
just two sides of the same coin.

A CASE STUDY ON ABSTRACTION


USING LAPTOP
Abstraction:
Abstraction is a process of hiding the implementation details and displaying the essential
features.
A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD
screen, wireless antenna, web camera, usb ports, battery, speakers etc. To use it, you don't
need to know how internally LCD screens, keyboard, web camera, battery, wireless antenna,
speakers works. You just need to know how to operate the laptop by switching it on. Think
about if you would have to call to the engineer who knows all internal details of the laptop
before operating it. This would have highly expensive as well as not easy to use everywhere
by everyone.
So here the Laptop is an object that is designed to hide its complexity.

Handbook II CSE II SEM

19

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions
How to abstract?
SOLUTION : By using Access Specifiers
Public -- Accessible outside the class through object reference.
Private -- Accessible inside the class only through member functions.
Protected -- Just like private but Accessible in derived classes also through member
functions.
Internal -- Visible inside the assembly. Accessible through objects.
Protected Internal -- Visible inside the assembly through objects and in derived classes
outside the assembly through member functions.
Lets try to understand by a practical example:-

public class Class1


{
int i;
//No Access specifier means private
public int j;
// Public
protected int k;
//Protected data
internal int m;
// Internal means visible inside assembly
protected internal int n;
//inside assembly as well as to derived classes
outside assembly
static int x;
// This is also private
public static int y;
//Static means shared across objects
[DllImport("MyDll.dll")]
public static extern int MyFoo();
//extern means declared in this assembly defined
in some other assembly
public void myFoo2()
{
//Within a class if you create an object of same class then you can access all data
members through object reference even private data too
Class1 obj = new Class1();
obj.i =10; //Error cant access private data through object.But here it is
accessible.:)
obj.j =10;
obj.k=10;
obj.m=10;
obj.n=10;
//
obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10;
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
}
Now lets try to copy the same code inside Main method and try to compile

Handbook II CSE II SEM

20

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions
[STAThread]
static void Main()
{
//Access specifiers comes into picture only when you create object of class outside
the class
Class1 obj = new Class1();
//
obj.i =10; //Error cant access private data through object.
obj.j =10;
//
obj.k=10;
//Error cant access protected data through object.
obj.m=10;
obj.n=10;
//
obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10; //Error cant access private data outside class
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
What if Main is inside another assembly
[STAThread]
static void Main()
{
//Access specifiers comes into picture only when you create object of class outside
the class
Class1 obj = new Class1();
//
obj.i =10; //Error cant access private data through object.
obj.j =10;
//
obj.k=10;
//Error cant access protected data through object.
//
obj.m=10; // Error cant access internal data outside assembly
//
obj.n=10; // Error cant access internal data outside assembly
//

obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10; //Error cant access private data outside class
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
In object-oriented software, complexity is managed by using abstraction.
Abstraction is a process that involves identifying the critical behavior of an object and
eliminating irrelevant and complex details.

Designing OOP Solutions: A Case Study


Designing solutions for an application is not an easy endeavor. Becoming an accomplished
designer takes time and a conscious effort, which explains why many developers avoid it like the
plague. You can study all the theories and know all the buzzwords, but the only way to truly
develop your modeling skills is to roll up your sleeves, get your hands dirty, and start modeling.
In this chapter, you will go through the process of modeling an office-supply ordering system.
Although this is not a terribly complex application, it will serve to help solidify the modeling
concepts covered in the previous chapters. By analyzing the case study, you will also gain a
better understanding of how a model is developed and how the pieces fit together.
Handbook II CSE II SEM

21

Dept. of Computer Science Engineering, School of Engineering, Anurag


Group of Institutions

Your company currently has no standard way for departments to order office supplies. Each
department separately implements its own ordering process. As a result, it is next to impossible
to track company-wide spending on supplies, which impacts the ability to forecast budgeting and
identify abuses. Another problem with the current system is that it does not allow for a single
contact person who could negotiate better deals with the various vendors.
As a result, you have been asked to help develop a company-wide office-supply ordering (OSO)
application. To model this system you will complete the following steps:
Now that you have analyzed the domain model of an OOP application, you are ready to
transform the design into an actual implementation. The next part of this book will introduce you
to the C# language. You will look at the .NET Framework and see how C# applications are built
on top of the framework. You will be introduced to working in the Visual Studio IDE and
become familiar with the syntax of the C# language. The next section will also demonstrate the
process of implementing OOP constructs such as class structures, object instantiation,
inheritance, and polymorphism in C#. You will revisit the case study introduced in this chapter
which time you will look at transforming the application design into actual implementation code.

Handbook II CSE II SEM

22