Wednesday, July 10, 2013

OOPS Concepts in .NET



* The object oriented programming (OOP) is a programming model 

where Programs are organized around object and data rather than 

action and logic.


* OOP allow decomposition of a problem into a number of entities called

Object and then builds data and function around these objects.

  • The Program is divided into number of small units called Object. The data and function are build around these objects.
  • The data of the objects can be accessed only by the functions associated with that object.
  • The functions of one object can access the functions of other object.

OOP has the following important features.


 Class:

A class is the core of any modern Object Oriented Programming language such as C#.

In OOP languages it is must to create a class for representing data. 

Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data. 

Class will not occupy any memory space and hence it is only logical 

representation of data.

To create a class, you simply use the keyword "class" followed by the class name:

class Employee
{

}




Object: 

Objects are the basic run-time entities in an object oriented system.They may represent a person,a place or any item that the program has to handle. 

"Object is a Software bundle of related variable and methods. "

“Object is an instance of a class”



Class will not occupy any memory space. Hence to work with the data represented by the class you must create a variable for the class, which is called as an object. 

When an object is created by using the keyword new, then memory will be allocated for the class in heap memory area, which is called as an instance and its starting address will be stored in the object in stack memory area.

 When an object is created without the keyword new, then memory will not be allocated in heap I.e. instance will not be created and object in the stack contains the value null.

When an object contains null, then it is not possible to access the members of the class using that object.

class Employee
{

}

Syntax to create an object of class Employee:-

Employee objEmp = new Employee();



All the programming languages supporting object oriented Programming will be supporting these three main concepts:
  1. Encapsulation
  2. Inheritance
  3. Polymorphism

Abstraction:

Abstraction is "To represent the essential feature without representing the back ground details."

Abstraction lets you focus on what the object does instead of how it does it.

Abstraction provides you a generalized view of your classes or object by providing relevant information.

Abstraction is the process of hiding the working style of an object, and showing the information of an object in understandable manner.

Real world Example of Abstraction:

Suppose you have an object Mobile Phone.

Suppose you have 3 mobile phones as following:-

Nokia 1400 (Features:- Calling, SMS)
Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera)
Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)

Abstract information (Necessary and Common Information) for the object "Mobile Phone" is make a call to any number and can send SMS."

so that, for mobile phone object you will have abstract class like following:-

    abstract class MobilePhone
    {
        public void Calling();
        public void SendSMS();
    }

    public class Nokia1400 : MobilePhone
    {

    }

    public class Nokia2700 : MobilePhone
    {
        public void FMRadio();
        public void MP3();
        public void Camera();
    }

    public class BlackBerry : MobilePhone
    {
        public void FMRadio();
        public void MP3();
        public void Camera();
        public void Recording();
        public void ReadAndSendEmails();

    }

Abstraction means putting all the variables and methods in a class which are necessary.

For example: - Abstract class and abstract method.

Abstraction is the common thing.

example: 
If somebody in your collage tell you to fill application form, you will fill your details like name, address, data of birth, which semester, percentage you have got etc.

If some doctor gives you an application to fill the details, you will fill the details like name, address, date of birth, blood group, height and weight.

See in the above example what is the common thing?

Age, name, address so you can create the class which consist of common thing that is called abstract class. 

That class is not complete and it can inherit by other class.

Encapsulation: 

Wrapping up data member and method together into a single unit (i.e. Class) is called Encapsulation.

Encapsulation is like enclosing in a capsule. That is enclosing the related operations and data related to an object into that object.

Encapsulation is like your bag in which you can keep your pen, book etc. It means this is the property of encapsulating members and functions.

    class Bag
    {
        book;
        pen;
        ReadBook();
    }


Encapsulation means hiding the internal details of an object, i.e. how an object does something.

Encapsulation prevents clients from seeing its inside view, where the behaviour of the abstraction is implemented.

Encapsulation is a technique used to protect the information in an object from the other object.

Hide the data for security such as making the variables as private, and expose the property to access the private data which would be public.
So, when you access the property you can validate the data and set it.

Example:

class Demo
{
   private int _mark;

   public int Mark
   {
     get { return _mark; }
     set { if (_mark > 0) _mark = value; else _mark = 0; }
   }
 }

Real world Example of Encapsulation:-

Let's take example of Mobile Phone and Mobile Phone Manufacturer
Suppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class), now by using machinery you are manufacturing a Mobile Phone(object) for selling, when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works.

This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class.

Example-2: 

TV operation 

It is encapsulated with cover and we can operate with remote and no need to open TV and change the channel.
Here everything is in private except remote so that anyone can access not to operate and change the things in TV.


Inheritance: 

When a class acquire the property of another class is known as inheritance.

Inheritance is process of object reusability.

For example, A Child acquire property of Parents.

public class ParentClass
    {
        public ParentClass()
        {
            Console.WriteLine("Parent Constructor.");
        }

        public void print()
        {
            Console.WriteLine("I'm a Parent Class.");
        }
    }

    public class ChildClass : ParentClass
    {
        public ChildClass()
        {
            Console.WriteLine("Child Constructor.");
        }

        public static void Main()
        {
            ChildClass child = new ChildClass();

            child.print();
        }
    }



Output:
    Parent Constructor.
    Child Constructor.
    I'm a Parent Class.

Polymorphism: 

Polymorphism means one name many forms.

One function behaves different forms.

In other words, "Many forms of a single object is called Polymorphism."

Real World Example of Polymorphism:

Example-1: 

A Teacher behaves to student.
A Teacher behaves to his/her seniors.
Here teacher is an object but attitude is different in different situation.

Example-2: 

Person behaves SON in house at the same time that person behaves EMPLOYEE in office.

Example-3: 

Your mobile phone, one name but many forms
  • As phone
  • As camera
  • As mp3 player
  • As radio
To Read Polmorphism in Detail click following link:-

Polymorphism in .Net




Difference between Abstraction and Encapsulation :-

Abstraction
Encapsulation
1. Abstraction solves the problem in the design level.

1. Encapsulation solves the problem in the implementation level.

2. Abstraction is used for hiding the unwanted data and giving relevant data.

2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world.


3. Abstraction lets you focus on what the object does instead of how it does it

3. Encapsulation means hiding the internal details or mechanics of how an object does something.

4. Abstraction- Outer layout, used in terms of design.
For Example:-
 Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.

4. Encapsulation- Inner layout, used in terms of implementation.
For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.




The easier way to understand Abstraction and encapsulation is as follows:-
Real World Example:- 

Take an example of Mobile Phone:- 

You have a Mobile Phone, you can dial a number using keypad buttons. Even you don't know how these are working internally. This is called Abstraction. You have the only information that is needed to dial a number. But not its internal working of mobile.

But how the Mobile Phone internally working?, how keypad buttons are connected with internal circuit? is called Encapsulation.

Summary:

"Encapsulation is accomplished by using Class. - Keeping data and methods that accesses that data into a single unit" 

"Abstraction is accomplished by using Interface. - Just giving the abstract information about what it can do without specifying the back ground details" 

"Information/Data hiding is accomplished by using Modifiers - By keeping the instance variables private or protected."


SQL Server Difference

1.Difference between Database Mail and SQL Mail

S.No Database Mail SQL Mail
1
Based on SMTP (Simple Mail Transfer Protocol).
Based on MAPI (Messaging Application Programming Interface).
2
Introduced in Sql Server 2005.
Used prior versions of Sql Server 2005.
3
No need to install Outlook.
Require Outlook to be installed.
4
More secure than Sql mail.
Less secure than Database mail.

2.Difference between Azure Table storage and SQL Azure
S.No Azure Table storage SQL Azure
1
It is built on top of the Azure Storage platform.
It is an SQL Server that has been configured to be hosted on top
of the Windows Azure in a high availability mode.
2
It comprises flexible or schema-less entities. No referential integrity between the tables, and no custom indexes.
It comprises standard SQL Tables with indexes and referential integrity.
3
It can scale massive amounts of data due to the partition key.
It may not scale as far as Azure Table storage.
4
Can be thought as single spreadsheet.
Look familiar to any .Net developer who has used Sql server 2008 prior.

3.Difference between DBMS and RDBMS
S.No DBMS RDBMS
1
Stands for DataBase Management System
Stands for Relational DataBase Management System
2
In dbms no relationship concept
It is used to establish the relationship concept between two database objects, i.e, tables
3
It supports Single User only
It supports multiple users
4
It treats Data as Files internally
It treats data as Tables internally
5
It supports 3 rules of E.F.CODD out off 12 rules
It supports minimum 6 rules of E.F.CODD
6
It requires low Software and Hardware Requirements.
It requires High software and hardware requirements.
7
DBMS is used for simpler business applications
RDBMS is used for more complex applications.
8
DBMS does not impose any constraints or security with regard to data manipulation
RDBMS defines the integrity constraint for the purpose of holding ACID PROPERTY
9
In DBMS Normalization process will not be present
In RDBMS, normalization process will be present to check the database table consistency
10
There is no enforcement to use foreign key concept compulsorily in DBMS
Although the foreign key concept is supported by both DBMS and RDBMS but its only RDBMS that enforces the rules
11
FoxPro, IMS are Examples
SQL Server, Oracle are examples

4.Difference between SQL Server 2000 and SQL Server 2005

S.No SQL Server 2000 SQL Server 2005
1
Query Analyser and Enterprise manager are separate.
Both are combined as SSMS(Sql Server management Studio).
2
No XML datatype is used.
.XML datatype is introduced.
3
We can create maximum of 65,535 databases.
We can create 2(pow(20))-1 databases.
4
Exception Handling mechanism is not available
Exception Handling mechanism is available
5
There is no Varchar(Max) data type is not available
Varchar(Max) data type is introduced.
6
DDL Triggers is not available
DDL Triggers is introduced

7
DataBase Mirroring facility is not available
DataBase Mirroring facility is introduced
8
RowNumber function for paging is not available
RowNumber function for paging is introduced
9
Table fragmentation facility is not available
Table fragmentation facility is introduced

10
Full Text Search facility is not available
Full Text Search facility is introduced

11
Bulk Copy Update facility is not available
Bulk Copy Update facility is introduced
12
Data Encryption concept is not introduced
.Cannot encrypt the entire database

13
Cannot compress the tables and indexes.
Can Compress tables and indexes.(Introduced in 2005 SP2)
14
No varchar(max) or varbinary(max) is available.
Varchar(max) and varbinary(max) is used.
15
Data Transformation Services(DTS) is used as ETL tool
SQL Server Integration Services(SSIS) is started using from this SQL Server version and which is used as ETL tool


5.Difference between Database Mail and SQL Mail
S.No Database Mail SQL Mail
1
Based on SMTP (Simple Mail Transfer Protocol).
Based on MAPI (Messaging Application Programming Interface).
2
Introduced in Sql Server 2005.
Used prior versions of Sql Server 2005.
3
No need to install Outlook.
Require Outlook to be installed.
4
More secure than Sql mail.
Less secure than Database mail.

6.Difference between Azure Table storage and SQL Azure
S.No Azure Table storage SQL Azure
1
It is built on top of the Azure Storage platform.
It is an SQL Server that has been configured to be hosted on top
of the Windows Azure in a high availability mode.
2
It comprises flexible or schema-less entities. No referential integrity between the tables, and no custom indexes.
It comprises standard SQL Tables with indexes and referential integrity.
3
It can scale massive amounts of data due to the partition key.
It may not scale as far as Azure Table storage.
4
Can be thought as single spreadsheet.
Look familiar to any .Net developer who has used Sql server 2008 prior.

7.Difference between DBMS and RDBMS
S.No DBMS RDBMS
1
Stands for DataBase Management System
Stands for Relational DataBase Management System
2
In dbms no relationship concept
It is used to establish the relationship concept between two database objects, i.e, tables
3
It supports Single User only
It supports multiple users
4
It treats Data as Files internally
It treats data as Tables internally
5
It supports 3 rules of E.F.CODD out off 12 rules
It supports minimum 6 rules of E.F.CODD
6
It requires low Software and Hardware Requirements.
It requires High software and hardware requirements.
7
DBMS is used for simpler business applications
RDBMS is used for more complex applications.
8
DBMS does not impose any constraints or security with regard to data manipulation
RDBMS defines the integrity constraint for the purpose of holding ACID PROPERTY
9
In DBMS Normalization process will not be present
In RDBMS, normalization process will be present to check the database table consistency
10
There is no enforcement to use foreign key concept compulsorily in DBMS
Although the foreign key concept is supported by both DBMS and RDBMS but its only RDBMS that enforces the rules
11
FoxPro, IMS are Examples
SQL Server, Oracle are examples

8.Difference between SQL Server 2000 and SQL Server 2005

S.No SQL Server 2000 SQL Server 2005
1
Query Analyser and Enterprise manager are separate.
Both are combined as SSMS(Sql Server management Studio).
2
No XML datatype is used.
.XML datatype is introduced.
3
We can create maximum of 65,535 databases.
We can create 2(pow(20))-1 databases.
4
Exception Handling mechanism is not available
Exception Handling mechanism is available
5
There is no Varchar(Max) data type is not available
Varchar(Max) data type is introduced.
6
DDL Triggers is not available
DDL Triggers is introduced

7
DataBase Mirroring facility is not available
DataBase Mirroring facility is introduced
8
RowNumber function for paging is not available
RowNumber function for paging is introduced
9
Table fragmentation facility is not available
Table fragmentation facility is introduced

10
Full Text Search facility is not available
Full Text Search facility is introduced

11
Bulk Copy Update facility is not available
Bulk Copy Update facility is introduced
12
Data Encryption concept is not introduced
.Cannot encrypt the entire database

13
Cannot compress the tables and indexes.
Can Compress tables and indexes.(Introduced in 2005 SP2)
14
No varchar(max) or varbinary(max) is available.
Varchar(max) and varbinary(max) is used.
15
Data Transformation Services(DTS) is used as ETL tool
SQL Server Integration Services(SSIS) is started using from this SQL Server version and which is used as ETL tool

Managing Session Integrity in .NET Core Web Applications: A Middleware Approach

 In our journey of developing a .NET Core web application, we encountered a peculiar challenge with our time-tracking feature. The applicati...