oop handout

30
Dept. of Computer Science Engineering, School of Engineering, Anurag Group of Institutions II B.Tech II Semester Handbook Object Oriented Programming Handbook II CSE II SEM 1

Upload: lalith-kartikeya

Post on 22-Dec-2015

214 views

Category:

Documents


0 download

DESCRIPTION

OOP HandoutOOP HandoutOOP Handout

TRANSCRIPT

Page 1: OOP Handout

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

II B.Tech II Semester

Handbook

Object Oriented Programming

SUB:OOPBranch: II CSE II SEM

Unit-I :

Handbook II CSE II SEM 1

Page 2: OOP Handout

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

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. Name Of The Topic No Of Classes Date Remarks

1 Need for oop paradigm 012 Classes, instances and

hierarchies01

3 Inheritance 014 OOPs concepts 015. Coping with complexity 016. Total Classes 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) Inheritanceb) Polymorphismc) Abstraction

d) Encapsulation9) Explain the importance of Object-oriented programming languages.10)Differentiate runtime and compile time polymorphism.

Applications:To differentiate the different styles of programmingTo learn the importance of oop

Handbook II CSE II SEM 2

Page 3: OOP Handout

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

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 ofclasses, objects, constructors, methods, access control, this keyword, garbage collection, overloading methodsand 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 constructors3) To make understand the different parameter passing technics

Lecture Plan:S.No Name Of The Topic No Of Classes Date Remarks1 History of java 022 Data types, Variables & their

scope02

3 Expression &control statements 024. Concepts of classes 025. Constructors, Access control 026. Garbage Collection, Method

overloading03

7. Nested and inner classes 02Total Classes 15

1) Explain about buzzwords of java?2) What are the data types used in java? Give examples?3) Explain about control statements in java?

Handbook II CSE II SEM 3

Page 4: OOP Handout

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

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 applicationof 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 compute1/1+1/2+1/3+--------+1/n1/2^0+1/2^1+1/2^2+------+1/2^n16) 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 structuresParameter passing technics

UNIT-III : Inheritance: Hierarchical abstractions, Base class object, subclass, subtype, substitutability, forms of

Handbook II CSE II SEM 4

Page 5: OOP Handout

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

inheritance- specialization, specification, construction, extension, limitation, combination, benefits ofinheritance, costs of inheritance. Member access rules, super uses, using final with inheritance, Polymorphism methodoverriding, abstract classes, the object class

Objectives:The major objectives of this unit are:To have an indepth knowledge of inheritanceUsage of final and super keywords

Lecture Plan:S.No Name Of The Topic No Of Classes Date Remarks1 Basics of inheritance. 01

2 Forms of inheritance. 013 Member access rules. 014. Final & super keyword uses 025. Polymorphism 026. Method overriding, Abstract

classes and object class02

Total Classes 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 inheritance8) 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?

Applications:Reusing the classes with the help of inheritance

Handbook II CSE II SEM 5

Page 6: OOP Handout

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

How to add new things to the existing class

Assignment Questions:Explain about benefits of inheritance. Define inheritance write a java program for simple inheritanceWhat 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 PlanS.No Name Of The Topic No Of

ClassesDate Remarks

1 Package basics 012 Difference between classes and

interface02

3 Interface basics 024. Exploring java.io package 01

Total Classes 06

Important Questions:

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?

Handbook II CSE II SEM 6

Page 7: OOP Handout

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

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 orresumptive models, exception hierarchy, usage of try, catch, throw, throws, finally, built in exceptions, creatingown 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 No Of Classes Date Remarks1 Exception handling 022 Exception handling using keywords 023 Creating

own exception sub classes.02

4. Exploring java.util. 01

Handbook II CSE II SEM 7

Page 8: OOP Handout

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

Total Classes 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, finally3) What are the checked Exceptions and Unchecked Exceptions? Explain some of these exceptions withan 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 javaprograms.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 inJava?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 programsHow to use different classes in java

Assignment Questions:

1) What are the checked Exceptions and Unchecked Exceptions? Explain some of these exceptions withan example and also give the difference between them.2) Explain the following: try, catch, throw, throws, finally3)What are the string handlings functions? Explain?

Handbook II CSE II SEM 8

Page 9: OOP Handout

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

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, creatingthreads, thread priorities, synchronizing threads, inter thread communication, thread groups, daemonthreads. Enumerations, autoboxing, annotations, generics.

Objectives:The major objectives of this unit are:Difference between multiprocessing and multithreadingInter thread communication

Impotant Questions1) 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 athread?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) Multithreadingc) Waiting state and Timed_waiting state d) Running statee) Preemptive scheduling f) Runnable interfaceg) Monitor h) Notify methodi) Join() method.

Applications:To Create multithreaded progamming

Handbook II CSE II SEM 9

Page 10: OOP Handout

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

S.No

Name Of The Topic No Of Classes

Date Remakes

1 Multi Threading 012 Creating threads,Thread

lifecycle01

3. Thread synchronization&inter thread communication

02

4. Enumerations,auto boxing 01Total Classes 05

Assignment Questions:

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, handlingmouse 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 managerlayoutmanager 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 Name Of The Topic No Of Classes Date remarks

Handbook II CSE II SEM 10

Page 11: OOP Handout

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

1 Event handling 01

2 Event handling though mouse,keyboard

02

3 AWT hierarchy,user interface components.

03

4. Lists panel 02

Total Classes 08

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 aregenerated by user actions. Explain?3) What are the methods supported by the following interfaces explain.a) Action Listener Interfaceb) Mouse Motion Listener Interfacec) Text listener Interface4) 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. Explainwith example?12)How you will add text area, button, checkbox, lists to an applet? Explain with skeleton Code?13)Write short notes ona) Jscrollpaneb) Jtabbedpanec) JToolbar

ApplicationsTo create GUI

Handbook II CSE II SEM 11

Page 12: OOP Handout

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

To handle eventsAssignment 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 eventsTo create graphics

UNIT VIII :

Applets: Concepts of Applets, difference between applets and applications, life cycle of an applet, types ofapplet, types of applets, creating applets. Passing parameters to applets.Swing: Introduction, limitations of AWT, MVC architecture, components, containers, exploring swing-JApplet, JFrame and JComponent, Icons and Labels, text fields, buttons- The JButton class, Check boxes, Radiobuttons, 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 Name Of The Topic No Of Classes Date remarks1 Applets, Life Cycle of

applets and Applet creation02

2 Passing parameters, Swing Introduction

02

3 MVC Architecture,components

02

4 Swing –jApplet,jframe 015. Jbutton classes 02

Total Classes 09Important Questions1) a) What are the advantages of Layout

Handbook II CSE II SEM 12

Page 13: OOP Handout

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

2) Explain the life cycle of an applet?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 JToggleButton10)What are the various dialog boxes available in Swing and how are they created?

ApplicationsTo 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 13

Page 14: OOP Handout

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

The Bank Account ClassSummaryThe 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 multi-threaded 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 14

Page 15: OOP Handout

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 15

Page 16: OOP Handout

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

OOP Case Study: The Bank Account Class (Part 2)by Christopher DigginsNovember 16, 2004SummaryMy 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 top-down 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 16

Page 17: OOP Handout

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 inherited-from 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.

Summary: Combining the Two Approaches

Handbook II CSE II SEM 17

Page 18: OOP Handout

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

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, speaker’s 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.How to abstract?

SOLUTION : By using Access Specifiers

Handbook II CSE II SEM 18

Page 19: OOP Handout

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

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.

Let’s 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 can’t 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[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 can’t access private data through object.            obj.j =10;

Handbook II CSE II SEM 19

Page 20: OOP Handout

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

      //      obj.k=10;     //Error can’t 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 can’t 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 can’t access private data through object.            obj.j =10;      //      obj.k=10;     //Error can’t access protected data through object.     //     obj.m=10; // Error can’t access internal data outside assembly    //      obj.n=10; // Error can’t access internal data outside assembly

       //     obj.s =10;  //Errror Static data can be accessed by class names only            Class1.x = 10;  //Error can’t 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.

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:

Handbook II CSE II SEM 20

Page 21: OOP Handout

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

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 21