oops concept
Object Oriented programming is a programming style
that is associated with the concept of Class, Objects and various other
concepts revolving around these two, like Inheritance, Polymorphism,
Abstraction, Encapsulation etc.
Let us try to understand a little
about all these, through a simple example. Human Beings are living forms,
broadly categorized into two types, Male and Female. Right? It’s true. Every
Human being (Male or Female) has two legs, two hands, two eyes, one nose, one
heart etc. There are body parts that are common for Male and Female, but then
there are some specific body parts, present in a Male which are not present in
a Female, and some body parts present in Female but not in Males.
All Human Beings walk, eat, see,
talk, hear etc. Now again, both Male and Female, performs some common
functions, but there are some specifics to both, which is not valid for the
other. For example: A Female can give birth, while a Male cannot, so this is
only for the Female.
Human Anatomy is interesting, isn't
it? But let's see how all this is related to C++ and OOPS. Here we will try to
explain all the OOPS concepts through this example and later we will have the
technical definitions for all this.
Class
Here we can take Human Being as a class. A class is a blueprint for any functional
entity which defines its properties and its functions. Like Human Being, having
body parts, and performing various actions.
Inheritance
Considering
Human Being
a class, which has properties like hands, legs, eyes
etc., and functions like walk, talk, eat, see etc. Male
and Female
are also classes, but most of the properties and
functions are included in Human Being
, hence they can inherit everything from class Human Being
using the concept of Inheritance.
Objects
My name is Abhishek, and I am an instance/object of class
Male
. When we say, Human Being, Male or Female, we just mean a kind,
you, your friend, me we are the forms of these classes. We have a physical
existence while a class is just a logical definition. We are the objects.
Abstraction
Abstraction means, showcasing only
the required things to the outside worked while hiding the details. Continuing
our example, Human Beings can talk, walk, hear, eat, but the details are hidden
from the outside world. We can take our skin as the Abstraction factor in our
case, hiding the inside mechanism.
Encapsulation
This concept is a little tricky to
explain with our example. Our Legs are binded to help us walk. Our hands, help
us hold things. This binding of the properties to functions is called
Encapsulation.
Polymorphism
Polymorphism is a concept, which
allows us to redefine the way something works, by either changing how it is
done or by changing the parts using which it is done. Both the ways have
different terms for them.
If we walk using our hands, and
not legs, here we will change the parts used to perform something. Hence this
is called Overloading.
And if there is a defined way of
walking, but I wish to walk differently, but using my legs, like everyone else.
Then I can walk like I want, this will be calls as Overriding.
OOPS Concept Definitions
Now, let us discuss some of the
main features of Object Oriented Programming which you will be using in
C++(technically).
1.
Objects
2.
Classes
3.
Abstraction
4.
Encapsulation
5.
Inheritance
6.
Overloading
7.
Exception Handling
Objects
Objects are the basic unit of OOP.
They are instances of class, which have data members and uses various member
functions to perform tasks.
Class
It is similar to structures in C
language. Class can also be defined as user defined data type but it also
contains functions in it. So, class is basically a blueprint for object. It
declare & defines what data variables the object will have and what
operations can be performed on the class's object.
Abstraction
Abstraction refers to showing only
the essential features of the application and hiding the details. In C++,
classes provide methods to the outside world to access & use the data
variables, but the variables are hidden from direct access. This can be done access
specifiers.
Encapsulation
It can also be said data binding.
Encapsulation is all about binding the data variables and functions together in
class.
Inheritance
Inheritance is a way to reuse once
written code again and again. The class which is inherited is called base calls
& the class which inherits is called derived class. So when, a derived
class inherits a base class, the derived class can use all the functions which
are defined in base class, hence making code reusable.
Polymorphism
It is a feature, which lets us
create functions with same name but different arguments, which will perform
differently. That is function with same name, functioning in different way. Or,
it also allows us to redefine a function to provide its new definition.
When an ASP.NET page runs, the page goes
through a life cycle in which it performs a series of processing steps. These
include initialization, instantiating controls, restoring and maintaining
state, running event handler code, and rendering. The following are the various
stages or events of ASP.Net page life cycle.
PreInit
PreInit
- Check the IsPostBack
property to determine whether this is the first time the page is being
processed.
- Create or re-create
dynamic controls.
- Set a master page
dynamically.
- Set the Theme property
dynamically.
Note: If the request is a postback then the values of the controls
have not yet been restored from the view state. If you set a control property
at this stage, its value might be overwritten in the next event.
Init
Init
- This event fires after each
control has been initialized.
- Each control's UniqueID is set
and any skin settings have been applied.
- Use this event to read or
initialize control properties.
- The "Init" event is
fired first for the bottom-most control in the hierarchy, and then
fired up the hierarchy until it is fired for the page itself.
InitComplete
- Until now the viewstate values
are not yet loaded, hence you can use this event to make changes to the
view state that you want to ensure are persisted after the next postback.
- Raised by the Page object.
- Use this event for processing
tasks that require all initialization to be complete.
OnPreLoad
- Raised after the page loads
view state for itself and all controls, and after it processes postback
data that is included with the Request instance.
- Before the Page instance raises
this event, it loads view state for itself and all controls, and then
processes any postback data included with the Request instance.
- Loads ViewState: ViewState data
are loaded to controls.
- Loads Postback data: Postback
data are now handed to the page controls.
Load
- The Page object calls the
OnLoad method on the Page object, and then recursively does the same for
each child control until the page and all controls are loaded. The Load
event of individual controls occurs after the Load event of the page.
- This is the first place in the
page lifecycle that all values are restored.
- Most code checks the value of
IsPostBack to avoid unnecessarily resetting state.
- You may also call Validate and
check the value of IsValid in this method.
- You can also create dynamic
controls in this method.
- Use the OnLoad event method to
set properties in controls and establish database connections.
Control PostBack Event(s)
- ASP.NET now calls any events on
the page or its controls that caused the PostBack to occur.
- Use these events to handle
specific control events, such as a Button control's Click event or a
TextBox control's TextChanged event.
- In a postback request, if the
page contains validator controls, check the IsValid property of the Page
and of individual validation controls before performing any processing.
- This is just an example of a
control event. Here it is the button click event that caused the postback.
LoadComplete
- Raised at the end of the
event-handling stage.
- Use this event for tasks that
require that all other controls on the page be loaded.
OnPreRender
- Raised after the Page object
has created all controls that are required in order to render the page,
including child controls of composite controls.
- The Page object raises the
PreRender event on the Page object, and then recursively does the same for
each child control. The PreRender event of individual controls occurs
after the PreRender event of the page.
- The PreRender event of
individual controls occurs after the PreRender event of the page.
- Allows final changes to the
page or its control.
- This event takes place before
saving ViewState, so any changes made here are saved.
- For example: After this event,
you cannot change any property of a button or change any viewstate value.
- Each data bound control whose
DataSourceID property is set calls its DataBind method.
- Use the event to make final
changes to the contents of the page or its controls.
OnSaveStateComplete
- Raised after view state and
control state have been saved for the page and for all controls.
- Before this event occurs,
ViewState has been saved for the page and for all controls.
- Any changes to the page or
controls at this point will be ignored.
- Use this event perform tasks
that require the view state to be saved, but that do not make any changes
to controls.
Render Method
- This is a method of the page
object and its controls (and not an event).
- The Render method generates the
client-side HTML, Dynamic Hypertext Markup Language (DHTML), and script
that are necessary to properly display a control at the browser.
UnLoad
- This event is used for cleanup
code.
- At this point, all processing
has occurred and it is safe to dispose of any remaining objects, including
the Page object.
- Cleanup can be performed on:
- Instances of classes, in other
words objects
- Closing opened files
- Closing database connections.
- This event occurs for each
control and then for the page.
- During the unload stage, the
page and its controls have been rendered, so you cannot make further
changes to the response stream.
- If you attempt to call a method
such as the Response.Write method then the page will throw an exception.

Web Role: Web roles in Windows Azure are special
purpose, and provide a dedicated Internet Information Services (IIS) web-server
used for hosting front-end web applications. You can quickly and easily deploy
web applications to Web Roles and then scale your compute capabilities up or
down to meet demands.
Worker Role: Worker roles are processes that can do some
work. For example, automatically compress uploaded images, do stuff whenever
something changes in your database, and get new messages from queues and
processes.
Queue: A Queue is something that contains a set of
messages and all messages must be in the queue.
Note: Web Roles,
Worker Roles and Queue are actually VMs.
The definitions above
may be insufficient to make your point crystal clear but that's okay, you will
not work on them in this article, you just need to understand Web Role here.
Comments
Post a Comment