Object-Oriented Programming Concepts
Basic Concepts of Oops
Value Type Data Types
1. Memory allocates at compile time in stacks
2. De-allocation will be take care by stacks
Reference Type Data types
1. Memory allocates at runtime time in heap
2. De-allocation will be take care by Garbage Collector
Classes
1. It’s a reference type data type
2. It’s a user defined data type
3. Collection of properties (data) and behaviour (functions) is called a class
Structures
1. It’s a value type data type
2. It’s a user defined data type
3. Collection of properties (data) and behaviour (functions) is called structures
4. We can’t define default constructor
5. It will not support inheritance
Object
1. Any real time entity is called an object
2. Instance of a class is also called as an object
Encapsulation
Wrapping (binding) up of some information (data and functions) within a single entity (class) is called an encapsulation.
Data Hiding
Restricting some information (private data/functions) within a single entity (class) is called as data hiding.
Polymorphism
Poly means many and morphism means actions
I.e. many actions with a single name is called polymorphism
Ex: Function overloading, operator overloading
Functions/Method Overloading
Defining same function name for more than one function body is called as function overloading.
CLR will select the appropriate function depending upon no. of arguments we are passing into the function. If no. of arguments is same, CLR will select the corresponding function with respect to the which type of argument we are passing.
Constructors
1. Constructors are useful to assign initial values while we are creating an object
2. Constructors are special functions in C#.net
3. Constructors are special procedures in VB.net
4. It must be define with public
5. Name of the constructor is same as a class name
6. Constructors will call automatically, whenever we are creating an object.
Types of constructors
1. Default Constructor
Will not receive any arguments
2. Parameterised Constructor
Will receive arguments
3. Constructor overloading
Within a class, if we have more than one constructor, then it’s called constructor overloading.
Static Data
1. Memory allocates only once throughout the program and it can be shared by each and every object
2. We can call static data directly using class name, without creating an object
Static Functions
1. Within static functions we can use static data or it must be a local variable
2. We can call static Functions directly using class name
3. We cannot use instance-data (class data/variable) in static functions
3. We can’t use ‘this’ object in static functions
Static Constructors
1. Static constructors are useful to assign initial values to the static variables
2. We cannot pass arguments into the static constructors.
3. It will not allow using access specifier and by default its ‘public’.
Static Class
1. If a class contains only static variables and/or static functions and/or static constructors, then that class is called as static class
2. We cannot create an object of static class.
‘Constant’ Data
1. Memory allocates only once thru out the program and it can be shared by each and every object
2. We have to assign initial value while we are declaring variable
3. Value in ‘const’ variable is fixed thru out the program and we cannot change
4. All ‘const’ variables are static by default. So, we can call ‘const’ variable directly using class name
‘Read only’ Data
1. ‘Read only’ instance
1. Memory allocates for each and every object
2. We can assign initial value or modify the value only in constructors
2. ‘Read only’ static
1. Memory allocates only once thru out the program and it can be shared by each and every object
2. We can assign initial value or modify the value only in static constructors.
Abstract Classes
1. A class which is not fully defined is called Abstract Class i.e. we may or may not implement the function within the current class. If we will not implement, at least we have to provide, signature / prototype of the function and we have to implement the function within derived function.
2. With in a class, if we have function signature/prototype, then that function is called as Abstract function. To declare abstract function, we have to use ‘abstract’ keyword.
3. With in a class, if we have at least one abstract function, then that class is called as abstract class. To define abstract class, we have to use ‘abstract’ keyword
4. We cannot create an object for abstract class
5. We can declare variables
6. We can also define constructors
Interfaces
1. Dot Net does not support multiple inheritance.
2. If we want to develop multiple type inheritance applications, we have to use, interfaces
3. Interface contains only abstract functions
4. It will not allow using access specified and by default its ‘public’
5. We can declare only ’static’ and ‘const’ variables
6. An interface inherits another interface
Final class
1. Final class cannot inherited
2. All static classes are final classes
Partial Class
Using partial classes we can split definition of a class over two or more source files.
No comments
No comments yet. Be the first.
Leave a reply
