What is OOP?
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.In order to clearly understand the object orientation, let’s take your “hand” as an example. The “hand” is a class. Your body has two objects of type hand, named left hand and right hand. Their main functions are controlled/ managed by a set of electrical signals sent through your shoulders (through an interface). So the shoulder is an interface which your body uses to interact with your hands. The hand is a well architected class. The hand is being re-used to create the left hand and the right hand by slightly changing the properties of it.
What is a 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.Ex :
public class Employee { }
Creating object :
Employee obj=new Employee();
According to the sample given above ,we can say that the student object, named objectStudent,
has created out of the Student class.
In the software world, though you may not have realized it, you have already used classes.
For example, the TextBox control, you always used, is made out of the TextBox class,
which defines its appearance and capabilities. Each time you drag a TextBox control,
you are actually creating a new instance of the TextBox class.
Object :
It is a real time entity.
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.
In pure OOP terms an object is an instance of a class.
Class is composed of three things name, attributes, and operations .OOPS Features :
If any programming language wants to be a object oriented programming language. then it needs to satisfy class and objects. then it needs to satisfy following four features. they are
1.Encapsulation
2.Inheritance
3.Polymorphism
4.Data abstraction.
C# is strong object oriented programming language.
Access Modifiers in c# :
Access Modifier | Description (who can access) |
---|---|
private | Only members within the same type. (default for type members) |
protected | Only derived types or members of the same type. |
internal | Only code within the same assembly. Can also be code external to object as long as it is in the same assembly. (default for types) |
protected internal | Either code from derived type or code in the same assembly. Combination of protected OR internal. |
public | Any code. No inheritance, external type, or external assembly restrictions. |
Accessibility :
Public - any item in the current assembly or any assembly that references the class, can access this member.
Protected - access is limited to the containing class or types derived from the containing class.
Internal - any item in the current assembly can access this member.
Protected internal - access is limited to the current assembly or types derived from the containing class.
Private - access is limited to the containing class.
Class Members in c# :
In C#, a class have following members,.
1.Data fields
2.Methods
3.Constructors
4.Destructors
5.Properties
6.Events
7.indexers.
Fields - instances of objects that are considered part of a class, normally holding class data.
Properties - methods on a class that are accessed as if they were fields on that class. A property can provide protection for a class field to keep it from being changed without the object's knowledge. For a more detailed understanding see Fields and Properties.
Methods - these define the actions that a class can perform by actioning a series of statements. Methods can take parameters that provide input data, and can return output data through parameters. Methods can also return a value directly, without using a parameter.
Events - a way of providing notifications about occurrences, such as button clicks or the successful completion of a method, to other objects. Events are defined and triggered using delegates.
Delegates - a type safe container of one or more function pointers.
Operators - these are terms or symbols such as +, *, <, and so on that perform operations on operands. Operators can be redefined to perform operations on custom data types.
Indexers - these allow an object to be indexed in a manner similar to arrays.
Constructors - methods that are called when the object is first created. They are often used to initialize the object's data.
Destructors - methods that are called by the runtime execution engine when the object is about to be removed from memory. They are generally used to make sure that any resources which need to be released are handled appropriately.
Constants - data members that are known at compile time.
No comments:
Post a Comment