1. An interactive look at the concepts of Object Oriented Programming in
C#. Click the button below to continue.
2. Oops Concepts in C#
Click on any of these objects listed above to learn more about the concepts
of Object Oriented Programming in C#. When you have completed all the
content areas from above click “Exit” button in the bottom left to exit.
Click to Watch Video on “ What is programming?” Click to Exit
4. Encapsulation
Encapsulation, also known as data hiding, is an important
object-oriented programming concept. It is the act of
concealing the functionality of a class so that the internal
operations are hidden, and irrelevant, to the programmer.
With correct encapsulation, the developer does not need
to understand how the class actually operates in order to
communicate with it via its publicly available methods and
properties; known as its public interface.
Encapsulation is essential to creating maintainable object-
oriented programs. When the interaction with an object
uses only the publicly available interface of methods and
properties, the class of the object becomes a correctly
isolated unit. This unit can then be replaced independently
to fix bugs, to change internal behaviour or to improve
functionality or performance.
In the car analogy this is similar to replacing a headlight
bulb. As long as we choose the correct bulb size and
connection (the public interface), it will work in the car. It
does not matter if the manufacturer has changed or the
internal workings of the bulb differ from the original. It may
even offer an improvement in brightness! Return to Main menu
5. Class
Car, bike, truck these all are belongs to vehicle class. These
Objects have also different different states and behaviours.
For Example car has state - colour, name, model, speed,
Mileage. as we;; as behaviours - distance travel.
The basic building blocks of object-oriented programming
are the class and the object. A class defines the available
characteristics and behaviour of a set of similar objects and
is defined by a programmer in code. A class is an abstract
definition that is made concrete at run-time when objects
based upon the class are instantiated and take on the
class's behaviour.
As an analogy, let's consider the concept of a 'vehicle' class.
The class developed by a programmer would
include methods such as Steer(), Accelerate() and Brake().
The class would also include properties such
as Colour, NumberOfDoors, TopSpeed and NumberOfWheel
s. The class is an abstract design that becomes real when
objects such as Car, RacingCar, Tank and Tricycle are
created, each with its own version of the class's methods
and properties.
Syntax to declare a Class
Syntax
class Class_Name
{
data member; method;
}
Return to Main menu
6. Polymorphism
The word polymorphism means having many forms. In object-oriented
programming paradigm, polymorphism is often expressed as 'one
interface, multiple functions'.
Polymorphism can be static or dynamic. In static polymorphism, the
response to a function is determined at the compile time. In dynamic
polymorphism, it is decided at run-time.
Static Polymorphism. The mechanism of linking a function with an
object during compile time is called early binding. It is also called static
binding. C# provides two techniques to implement static
polymorphism. They are:
Function Overloading
You can have multiple definitions for the same function name in the
same scope. The definition of the function must differ from each other
by the types and/or the number of arguments in the argument list. You
cannot overload function declarations that differ only by return type.
Dynamic Polymorphism
C# allows you to create abstract classes that are used to provide partial
class implementation of an interface. Implementation is completed
when a derived class inherits from it. Abstract classes contain abstract
methods, which are implemented by the derived class. The derived
classes have more specialized functionality.
Return to Main menu
7. Inheritance
Inheritance is an interesting object-oriented programming
concept. It allows one class (the sub-class) to be based upon
another (the super-class) and inherit all of its functionality
automatically. Additional code may then be added to create a
more specialised version of the class. In the example of
vehicles, sub-classes for cars or motorcycles could be created.
Each would still have all of the behaviour of a vehicle but can
add specialised methods and properties, such as 'Lean()' and
'LeanAngle' for motorcycles.
Some programming languages allow for multiple
inheritance where a sub-class is derived from two or more
super-classes.
Diagram
Return to Main menu
8. Abstraction
Abstraction is the process of representing simplified versions
of real-world objects in your classes and objects. The car class
does not describe every possible detail of a car, only the
relevant parts for the system being developed. Modelling
software around real-world objects can vastly reduce the time
required to understand a solution and be able to develop and
maintain it.
Return to Main menu
9. Array
An array stores a fixed-size sequential collection of elements of
the same type. An array is used to store a collection of data, but it
is often more useful to think of an array as a collection of variables
of the same type stored at contiguous memory locations.
Instead of declaring individual variables, such as number0,
number1, ..., and number99, you declare one array variable such
as numbers and use numbers[0], numbers[1], and ..., numbers[99]
to represent individual variables. A specific element in an array is
accessed by an index.
All arrays consist of contiguous memory locations. The lowest
address corresponds to the first element and the highest address
to the last element.
Return to Main menu