fundamentals of oops in .net

23
Fundamentals of OOPS in .NET By Harman

Upload: harman-bajwa

Post on 19-Jan-2015

2.844 views

Category:

Education


0 download

DESCRIPTION

This presentation is very useful for the Beginners who want to know the BASE on which OOPS work on .

TRANSCRIPT

Page 1: Fundamentals of oops in .Net

Fundamentals of OOPS in .NET

By Harman

Page 2: Fundamentals of oops in .Net

2

Introduction

• OOPS

• OOP is a design philosophy. It stands for Object Oriented Programming. Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages (C, Pascal, etc.). Everything in OOP is grouped as self sustainable "objects". Hence, you gain re-usability by means of four main object-oriented programming concepts.

Classification: Confidential 2011-10-04

Page 3: Fundamentals of oops in .Net

3

Objects

• An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can grip something or a Student (object) can give the name or address. In pure OOP terms an object is an instance of a class.

Classification: Confidential 2011-10-04

Page 4: Fundamentals of oops in .Net

4

Class

• A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.

• public class Student

• {

• }

• According to the sample given below we can say that the student object, named objectStudent, has created out of the Student class.

• Student objectStudent = new Student();

Classification: Confidential 2011-10-04

Page 5: Fundamentals of oops in .Net

5

Continues

• As an example, there may be thousands of other bicycles in existence, all of the same make and model. Each bicycle has built from the same blueprint. In object-oriented terms, we say that the bicycle is an instance of the class of objects known as bicycles.

Classification: Confidential 2011-10-04

Page 6: Fundamentals of oops in .Net

6

Encapsulation (or information hiding)

• The encapsulation is the inclusion within a program object of all the resources need for the object to function - basically, the methods and the data. In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties.

• encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system.

Classification: Confidential 2011-10-04

Page 7: Fundamentals of oops in .Net

7

Association

• Association is a (*a*) relationship between two classes. It allows one object instance to cause another to perform an action on its behalf. Association is the more general term that define the relationship between two classes, where as the aggregation and composition are relatively special.

• Example next slide ->

Classification: Confidential 2011-10-04

Page 8: Fundamentals of oops in .Net

8

Example of Association

public class StudentRegistrar

{

public StudentRegistrar ();

{

new RecordManager().Initialize()

}}

• we can say that there is an association between StudentRegistrar and RecordManager

Classification: Confidential 2011-10-04

Page 9: Fundamentals of oops in .Net

9

Abstraction

• Abstraction is another good feature of OOPS. Abstraction means to show only the necessary details to the client of the object.

For Ex:-

• We don’t know the inner details of monitor ? What happen when you switch ON Monitor? Does this matter to you what is happening inside the Monitor? No Right, Important thing for you is weather Monitor is ON or NOT.

• When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it!!

• This is abstraction; show only the details which matter to the user.

• abstraction says expose only the details which are concern with the user (client) of your object. So the client who is using your class need not to be aware of the inner details like how you class do the operations? He needs to know just few details.

Classification: Confidential 2011-10-04

Page 10: Fundamentals of oops in .Net

10

Abstract Class

• If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated.

• abstract public class Vehicle { }

• Above, an abstract class named Vehicle has been defined. We may use the fields, properties and member functions defined within this abstract class to create child classes like Car, Truck, Bike etc. that inherit the features defined within the abstract class.

• We can also have virtual methods defined in an abstract class. The virtual method may have its default implementation, where a subclass can override it when required.

Classification: Confidential 2011-10-04

Page 11: Fundamentals of oops in .Net

11

Interface

• An interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default,

Classification: Confidential 2011-10-04

Page 12: Fundamentals of oops in .Net

12

Diff b/w Abstract class & Interface

• A class may inherit only one abstract class, but may implement multiple number of Interfaces. Say a class named Car needs to inherit some basic features of a vehicle, it may inherit from an Abstracts class named Vehicle.

• Members of an abstract class may have any access modifier, but members of an interface are public by default, and cant have any other access modifier.

• Abstract class methods may OR may not have an implementation, while methods in an Interface only have a definition, no implementation.

Classification: Confidential 2011-10-04

Page 13: Fundamentals of oops in .Net

13

Continue Abstract Class

• Interface definition begins with a keyword interface so it is of type interface

• Abstract classes are declared with the abstract keyword so it is of type class

• Interface has no implementation, but they have to be implemented.

• Abstract class’s methods can have implementations and they have to be extended.

Classification: Confidential 2011-10-04

Page 14: Fundamentals of oops in .Net

14

Implicit/Explicit IMP-

• .Net support multiple implementations, the concept of implicit and explicit implementation provide safe way to implement methods of multiple interfaces by hiding, exposing or preserving identities of each of interface methods, even when the method signatures are the same.

• Just an interface

interface IDisposable

{

void Dispose();

}

Classification: Confidential 2011-10-04

Page 15: Fundamentals of oops in .Net

15

Ex- Implicit & Explicit

class Student : IDisposable

{

public void Dispose()

{

Console.WriteLine("Student.Dispose");

}

void IDisposable.Dispose()

{

Console.WriteLine("IDisposable.Dispose");

}

}

Implicit

Explicit

Classification: Confidential 2011-10-04

Page 16: Fundamentals of oops in .Net

16

What is Inheritance?

• Ability of a new class to be created, from an existing class by extending it, is called inheritance.

public class Exception

{

}

public class IOException : Exception

{

}

• According to the previous example the new class (IOException), which is called the derived class or subclass, inherits the members of an existing class (Exception), which is called the base class or super-class.

• The class IOException can extend the functionality of the class Exception by adding new types and methods and by overriding existing ones.

Classification: Confidential 2011-10-04

Page 17: Fundamentals of oops in .Net

17

What is Polymorphism?

• Polymorphisms is a generic term that means 'many shapes'. More precisely Polymorphisms means the ability to request that the same operations be performed by a wide range of different types of things.

• In OOP the polymorphisms is achieved by using many different techniques named method overloading, operator overloading and method overriding,

• Method Overloading

The method overloading is the ability to define several methods all with the same name.

• What is Operator Overloading?

Operator overloading is the most evident example of Polymorphism. In operator overloading, an operator is ‘overloaded’ or made to perform additional functions in addition to what it actually does. For e.g. we can overload the “+” operator to add two complex numbers or two imaginary numbers.

X= a + b //+ is overloaded to add two integers, float etcFew operators like :: cannot be overloaded.

Classification: Confidential 2011-10-04

Page 18: Fundamentals of oops in .Net

18

Continue:-

• Method overriding is a language feature that allows a subclass to override a specific implementation of a method that is already provided by one of its super-classes. A subclass can give its own definition of methods but need to have the same signature as the method in its super-class.

Classification: Confidential 2011-10-04

Page 19: Fundamentals of oops in .Net

19

Class diagrams

• A class diagrams are widely used to describe the types of objects in a system and their relationships. Class diagrams model class structure and contents using design elements such as classes, packages and objects.

Classification: Confidential 2011-10-04

Page 20: Fundamentals of oops in .Net

20

What is MVC architecture?

• The Model-View-Controller (MVC) architecture separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes.

• Model: specified DataSet and typed DataSet are the most common use of the model.

• View: The ASPX and ASCX files generally handle the responsibilities of the view.

• Controllers: The handling of events or the controlling is usually done in the code-behind class.

Classification: Confidential 2011-10-04

Page 21: Fundamentals of oops in .Net

21

Data Access Layer

• Used while retrieving the information to and from the database .

• The data access layer (DAL), which is a key part of every n-tier system, is mainly consist of a simple set of code that does basic interactions with the database or any other storage device.

• These functionalities are often referred to as CRUD (Create, Retrieve, Update, and Delete).

• The data access layer need to be generic, simple, quick and efficient as much as possible. It should not include complex application/ business logics.

Classification: Confidential 2011-10-04

Page 22: Fundamentals of oops in .Net

22

Business Logic Layer/Presentation Layer

• Business Logic Layer include the Business logic example classes , methods permanents to be passed to execute it using Special procedures to the database.

• Presentation layer represents the USER INTERFACE which will be presented to the User , it uses browsers like Internet explorer to convert the business logic to human readable form .

Classification: Confidential 2011-10-04

Page 23: Fundamentals of oops in .Net

Fundamentals of OOPS

HarmanApplication Developer

• Thanks