Tag Archives: object oriented programming

The philosophy of object oriented programming


Programmatically today is good. I added user and membership tables using aspnet_regsql.exe in a database. After creating it I connected it through Provider class in web.config.
Next, I created roles programmatically and assign roles to users.
This is great. I wanted to do it for last two three days and failed. But the method is not very difficult at all.
You use a command line code like this:
aspnet_regsql.exe -d -E -A all
pressing enter the required classes(tables) will have added to the database. Now using the proper connection string you can get connected to the database.
The next steps are pieces of cakes as you drag web controls from Login toolbox. The default classes automatically attached and next thing you write down a class which inheriting from SqlProvider overrides the methods to create Roles and assign users to that roles.
Asp.Net ships with plenty of classes that you can use with your classes and create objects accordingly.
This is the greatness of Object Oriented Programming.
I find it Philosophical getting reflections of the real world. Don’t you?

What this OOP does in ASP.NET


This qustion really haunts beginners. When you build up a web site with the help of Visual Studio 2005 or 2008 or 2010, the basic steps are easy. In fact, it seems that it’s a piece of cake. But when you are asked to write down a class of your own which will control the Default.aspx page to display something it turns around to difficulties.
Even, the seasoned computer addicts are puzzled at some points when they are asked to go through the basic concepts of Object Oriented Programming.
They are confused. They eventually ask silly questions like : what this object oriented programming does in ASP.NET?
This questions really haunt beginners. What actually happens? How it happens? Why should I learn object oriented programming to build web site etc.
I want to understand this from the angle of a student. And I’ll try to write about it in a few installments so that a beginner like me can start from zero and build up a web site that will talk to the datas in a databse and make things happen.

Three tier architecture in ASP.NET


Just now I’m learning and building a project based on three tier architecture.
This is extremely useful especially when you’re going to build an application that would be solid, hacker-proof and could be extended in future.
The first tier is Presentation. This will be viewed and used by the end user. Like you view a web page, perticipate etc.
The second tier is Business tier. It plays the role of a bridge between upper and lower tier. In the lower tier there is Data tier. Business tier stays between them, ie; Presentation and Data, maintaining the connection.
How this happens I’ll explain.
Being a developer, in the one hand you might have many end users. The number of end users are varying. It could be very large. So you have to build a site that’d sustain that pressure and will not be broken.
On the other hand you have your client. They could be also very demanding. Moreover, lately after a site has been built up, client might want to extend the application.
So the Business tier, where client will operate, should be flexible. To maintain that flexibility, you write down your own classes that will have thier own members. This classes could be static. There could be struct for maintaining speed. You know struct is mainly used as data container. Speed is a factor in a dynamic site.
In the lower section, there is the final tier Data. It is called Data tier or Database tier. The valuable data resides in Data tier.
The whole architecture goes in a sequential flow so that from the Presentation tier you can not jump onto the Data tier. The Businaess tier not only stands between them but also guards the Data tier controlling the end user’s demand and query against the Data.
Altogether, the whole three tier architecture not only looks impregnable but also stands solid against any malicious codes.
It looks like this:
1) Presentation tier
2) Business tier
3) Data tier
2) Business tier
1) Presentation tier
The flow moves down and goes up accordingly.
A note for the beginners like me: the Object Oriented Programming solidly displays its main characteristics in the Business tier where you write down the classes like Generic Data Access, Database Access, many utility classes like sending mails etc.
In your classes you can call the default .NET classes accordingly, create their instances and use them.
At the end of the day the application is ready, dynamic and kicking.
Best of luck!

Object Oriented Programming


I am not a celeb. People never search for my story of life, nor be interested to listen. So in a second thought I decided not to elaborate my unfinished autobiography 🙂
I started this blog having a special intention to help people in ASP.NET. Basic questions usually disturb us. Finding answers we are relieved and get the neccessary motivation for movimg forward.
So helping people is my primary motivation to adopt this age-old medium.
After I started learning ASP.NET, C#, I still think that I have to go miles than I have already traversed. But I can at least try to help.
Let me try.
Like if you are a student of Object Oriented Programming and ask how to learn object oriented programming then these two chapters are must read.
The second part

Difference between function and method


In PHP I took reference from Beginning PHP 5 and MySql 5 By W Jason Gilmore, Appress book.
A method is quite similar to a function, except that it is intended to define the behavior of a particular class. Like a function, a method can accept arguments as input and can return a value to the caller. Methods are also invoked like functions, except that the method is prefaced with the name of the object invoking the method, like this:

Methods are created in exactly the same fashion as functions, using identical syntax. The only
difference between methods and normal functions is that the method declaration is typically
prefaced with a scope descriptor. The generalized syntax follows:
scope function functionName()
/* Function body goes here */
For example, a public method titled calculateSalary() might look like this:
public function calculateSalary()
return $this->wage * $this->hours;
In this example, the method is directly invoking two class fields, wage and hours, using the $this keyword. It calculates a salary by multiplying the two field values together, and returns the result just like a function might. Note, however, that a method isn’t confined to working solely with class fields; it’s perfectly valid to pass in arguments in the same way you can with a function.
Methods are invoked in almost exactly the same fashion as functions. Continuing with the previous example, the calculateSalary() method might be invoked like so:
$employee = new staff(“Janie”);
PHP supports six method scopes: public, private, protected, abstract, final, and static. The first five scopes are introduced in this section. The sixth, is static.
$salary = $employee->calculateSalary();
Public methods can be accessed from anywhere, at any time. You declare a public method by
prefacing it with the keyword public, or by foregoing any prefacing whatsoever. The following
example demonstrates both declaration practices, in addition to demonstrating how public
methods can be called from outside the class:

class Visitors
public function greetVisitor()
echo "Hello
function sayGoodbye()
echo "Goodbye
$visitor = new Visitors();

Now let’s see what happens in ASP.NET, or to be precise in C# :
I got a good answer from EggHeadCaffe
The major difference between methods and functions is that methods called by the reference variables called objects where as the functions do not having any reference variables.methods are invoked using objects.wheres as in case of functions here is no quesion of objects.we call it directly.
And yet another good answer from StackOverflow
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

It is implicitly passed the object for which it was called
It is able to operate on data that is contained within the class (remembering that an object is an instance of a class – the class is the definition, the object is an instance of that data)
(this is a simplified explanation, ignoring issues of scope etc.)



I won’t spend much time on explaining Object Oriented Programming as there already million of words have been written by the experts and few of them are really worth reading (to name a few, I presently read Pter Lavin’s book on OO in PHP finding it simply brilliant.).
What I just try to do is very simple, find a simmilarity between creating ‘Class’ in ASP.NET and PHP and using access modifiers I set their properties from private to public.
First, let me show how Class being written in ASP.NET
Let me crate a class called Person

//creting class
class Person
private _name;
public Name
return _name;
_name = value;
//crating instance
Person person1 = new Person();
person1.Name = “Person1’s Name”;
Response.Write(“Person1’s Name is ” + person1.Name);

Next in PHP I follow the same procedure

And the page looks like this:

The thing is, I tried to keep codes of both great dynamic web language almost similar. So that one can follow the simmilarity between those get and set properties that make private variables public so that you can ultimately access them in different class, in different situation.
Hope, curious people find it interesting.