Pls answer this question fast..
1. With an example briefly describe how encapsulation provides modularity.
2. With the help of a suitable example explain the concept of Objects and classes.
3. With a re world example explain what are Objects in OOP (Object Oriented Programming).
Answers
Atomic Object
Lecture Notes on Object-Oriented Programming
Encapsulation & Modularity
This collection of notes on OOP was never meant to stand alone. It also represents a view of OO circa early to mid 1990s. Some people still find them useful, so here they are, caveat emptor. Special thanks to Gilbert Benabou for taking to time to compile the first printable version of this document and inspiring us to provide it.
[ PDF ] Printable Version
TABLE OF CONTENTS
Motivation for OO
The OO Paradigm
Visualizing Program Execution
OO Naming Conventions
The Object Model
Abstraction and Identity
Object-Oriented Messaging
Encapsulation & Modularity
Object-Oriented Hierarchy
Object-Oriented Typing
OO Concurrency & Persistence
The OO Development Process
OO Analysis Techniques
Pitfalls in OO Analysis
UML Notation
CRC Cards
OO Class Relationships
Object Oriented Aggregation
Object Oriented Interitance
Other Object Oriented Class Relationships
Object Oriented Instantiation
Object Oriented Polymorphism
Review of OO Programming
The Quality of Classes and OO Design
Encapsulation
We encapsulate the details of a class inside its private part so that it is impossible (and not just suggested) for any of the class's clients to know about or depend upon these details.
The ability to change the representation of an abstraction (data structures, algorithms) without disturbing any of its clients is the essential benefit of encapsulation.
Aside - should I say the "class's clients" or the "object's clients"?
Why encapsulate and hide?
You can delay the resolution of the details until after the design.
You can change it later without a ripple effect.
It keeps your code modular.
How we do this separation is with two separate pieces for each class, an implementation and an interface.
Modularity
Modularity is closely tied with encapsulation; think of modularity as a way of mapping encapsulated abstractions into real, physical modules.
The C/C++ convention is to create two files for each class: a header file (.h suffix) for the class interface, and an implementation file (.c, .cp, .cpp, .C suffix) for the code of the class.
Booch gives two goals for defining modules. Make a module cohesive (shared data structures, similar classes) with an interface that allows for minimal inter-module coupling.
Other considerations: team work, security, documentation.
Important to remember that the decisions concerning modularity are more physical issues, whereas the encapsulation of abstractions are logical issues of design.
It is possible to "over modularize". This can increase documentation costs and make it hard to find information.
Classes and objects are the fundamental components of OOP's. Often there is a confusion between classes and objects. In this tutorial, we try to tell you the difference between class and object.
First, let's understand what they are,
What is Class?
What is an Object?
What is the Difference Between Object & Class?
Concept of Classes and Objects
Example Code: Class and Object
Object and Class Example: main outside class
What is Class?
A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.
Syntax
class <class_name>{
field;
method;
}
What is an Object?
An object is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. Object determines the behavior of the class. When you send a message to an object, you are asking the object to invoke or execute one of its methods.
From a programming point of view, an object can be a data structure, a variable or a function. It has a memory location allocated. The object is designed as class hierarchies.
Syntax
ClassName ReferenceVariable = new ClassName();
What is the Difference Between Object & Class?
A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects of a certain kind.
An object is a specimen of a class. Software objects are often used to model real-world objects you find in everyday life.
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes), and code, in the form of procedures (often known as methods). A feature of objects is an object's procedures that can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self"). In OOP, computer programs are designed by making them out of objects that interact with one another.[1][2] OOP languages are diverse, but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types.