0% found this document useful (0 votes)
12 views9 pages

OOP Definitions (OOP C#)

The document provides an overview of Object-Oriented Programming (OOP) in C#, highlighting its key concepts such as encapsulation, abstraction, inheritance, and polymorphism, which enhance code reusability and maintainability. It explains the importance of access modifiers, constructors, properties, and the distinction between static and non-static members. Additionally, it includes examples to illustrate these concepts, such as modeling a college student and the relationships between classes.

Uploaded by

wiyehif961
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

OOP Definitions (OOP C#)

The document provides an overview of Object-Oriented Programming (OOP) in C#, highlighting its key concepts such as encapsulation, abstraction, inheritance, and polymorphism, which enhance code reusability and maintainability. It explains the importance of access modifiers, constructors, properties, and the distinction between static and non-static members. Additionally, it includes examples to illustrate these concepts, such as modeling a college student and the relationships between classes.

Uploaded by

wiyehif961
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

OOP definitions (OOP C#)

What is OOP :- object oriented programming (oop) is


programming paradigm ( way of thinking or structuring
for code )
why :- it has close correspondence between real word
objects and oop classes , it is very centralized around
object concept, it also aims to reduce complexity and
increase reusability by grouping related data and
behaviors into objects.
to make a system as an OOP system identify where
(objects) and what the (methods) we use to message
others and what the )relation( between the objects,
.oop based on four concepts (encapsulation ,
abstraction , inheritance , polymorphism) which help
programmers control and access data while improving
code readability, maintainability, and reusability
. There are also principles that make our code much
better like SOLID principles , DRY

● Let us model a college student. (EXAMPLE)


(fields)
Department, Registration year, Attended Classes,
GPA
Personnel: Name, Birthday, Gender, Email, Address
methods
Add a new registered course?
Get or update GPA? …..
Encapsulation :- it is one of the concepts in OOP that
means wrapping (encapsulate) related data and functions
in one unit (class) this data is hidden and not accessible
directly by external code
Why:- it is preventing the object from an invalid state and
make sure sensitive data is hidden from user (By using
properties) get and set( we can access and update the
value of a private field) . it also Reducing System
Complexity .(make private as you know)
it protects the integrity of the object’s
minimize how much external code needs to know about
the object's inner workings.( reduce outsiders’
dependency (coupling))
Example:- in the car class there are private fields like
fuellevel or enginestatus , which can only be modified
through public methods like reful() , or startEnging() ;

Access modifiers :- are keywords used to specify the


level of access to method classes and variables.
modifier Description
Public Accessible from anywhere in the
application.
Private Accessible only within the class where it is
declared.
Protected Accessible within the declaring class and
its derived classes.
internal Accessible within the same assembly
(project).
Abstraction:- it is one of the concepts in OOP that
means hiding certain details while showing most essential
in a given context (specific information) , hide how from
what .
. hide : Separate (hide) implementation (How) from
interface (What)
. Hide data members & member functions as much as
possible
…Abstraction can be achieved with either abstract
classes or interfaces.
Why :- it allows to focus on interfaces at a high level
without needing to understand the underlying
implementation.
Example:- in a car class , might have methods like
drive() and stop() , which abstract complex mechanics
of how the car operates.
Abstract method:- can only be used in an abstract
class, and it does not have a body. The body is provided
by the derived class (inherited from).
Abstract class:- it is a class that cannot be used to
create instance from itself (objects) It can have abstract
methods (methods without implementation), as well as
implemented functions
. Describes the behavior of an incomplete class,
---Future derived classes add their particular
implementations ---can have
state/some implemented functions
Interface:- interface is a completely "abstract class",
which can only contain abstract methods and properties
(with empty bodies)
Example : if we have a class chap is abstract , this
abstract class has 2 derived class circle and rectangle
base class has abstract method named getArea() => no
implementation on shape class but circle() will give
implementation ( PI * r * r) and rectangle will give
implementation ( l * r)
 Inheritance: it is inheriting fields and methods from
one class to another. the derived class has is a
relationship with base class ( student is a person ,
Circle is a shape )
o Derived Class (child) - the class that inherits from another class
o Base Class (parent) - the class being inherited from

Why:- it avoids duplicating code by Code Reusability


Example:- we have base class called shape ,
twoDimensionalShape and
threeDimensionalShape take inherited from it
twoDimensionalShape has subclasses like
circle ,rectangle and so on (draw it a MUL class)

Shape

├── TwoDimensionalShape
│ ├── Circle
│ ├── Rectangle

└── ThreeDimensionalShape
├── Cube
├── Sphere
Polymorphism:- this word means has many forms it
is the ability for an object to behave in multiple ways it is
making us to write generic code

Why: In runtime, the method will be called based on the


object's actual type (base or derived), enabling dynamic
behavior. (many forms)  This Allow us to write generic
code
There are two types of polymorphism :
Overloading: 2+ methods (give a sum example a+b with
different signature)

○ compile time polymorphism (Aka static/early binding)

○ Same class
○ Same name but different signature (number or type of
parameters)

Note method signature (name of method , parameter type ,


parameter order , number of parameter )

Overriding:
○run-time polymorphism (Aka dynamic/late binding)

○ Between base class and child class


○ Same name and same parameters
Example:- We have a base class Shape and two
derived classes: Circle and Rectangle. The base class
defines a method GetArea() as virtual (or abstract). Each
derived class provides its specific implementation for the
method
Virtual method :- is a method in a base class that has a
default implementation but can be overridden in derived
classes to provide a more specific behavior. The keyword
virtual allows the method to support runtime
polymorphism.( child class may not make override from this base class) (child
class use override to override this method ).
Class:- A class is a template that defines the structure
and behavior of objects(description for object). It specifies the
properties (fields) and actions (methods) that objects
created from the class can have.
Object: An object is an instance of a class. It provides
access to public (non-static) methods and properties of
the class and represents a specific entity with its own
state and behavior.
Usage: An object is used to perform operations and store
data specified based on the class definition.
Constractor:- It is a special method Automatically called
when an object (instance of class) is created Same name
as the class itself and no return type default or
Parameterized constructor
Property: A way to encapsulate and control access to a
field, often with get and set accessors.(promote
encapsulation)
Get :- used to access/read fields.(return value)
Set :- used to mutate/change fields.
Fields :- A field is a variable that is a member of a class
or struct, used to store data or state for objects or
instances of that class/struct.
Read-only Modifier: A keyword in C# used to declare a
field whose value can only be assigned during its
declaration or in the constructor, ensuring it cannot be
modified afterward.
Namespace:- it is a way to organize the programming
code and group classes, interfaces and other related
types together into a single logical unit. It is used to
divide the programming code into organized units that
can be better managed, especially for large projects.
Static:-
Definition: Static members (such as variables and
methods) are common to all objects of a class. They can
be accessed using the class name directly without having
to create an object.

Usage: They are used to store data or methods that must


be common to all objects of the same class.
Non static:-
Definition: Non-static members are related to each
object individually. An object of the class must be created
to access these members.
Usage: Used to store data and functions that depend on
a specific state of each object.
Structuring programming :- It is a programming
paradigm focused on functions and methods to organize
the code and make it reusable.

You might also like