0% found this document useful (0 votes)
20 views27 pages

Oop 2

The document provides an overview of class libraries, user-defined data types (classes, structs, interfaces, enums), and access modifiers in programming. It details the characteristics and usage of structs, including their value type nature and limitations regarding inheritance, as well as the principles of Object-Oriented Programming (OOP) such as encapsulation, inheritance, polymorphism, and abstraction. Additionally, it explains how access modifiers control the visibility of class members and the structure of properties in C#.

Uploaded by

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

Oop 2

The document provides an overview of class libraries, user-defined data types (classes, structs, interfaces, enums), and access modifiers in programming. It details the characteristics and usage of structs, including their value type nature and limitations regarding inheritance, as well as the principles of Object-Oriented Programming (OOP) such as encapsulation, inheritance, polymorphism, and abstraction. Additionally, it explains how access modifiers control the visibility of class members and the structure of properties in C#.

Uploaded by

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

Class Library

● It is a collection of classes, interfaces, and other types that can be

used in multiple projects to provide reusable functionality.

● They are typically compiled into dynamic link libraries (DLL) and

can be referenced by other applications, it is commonly used to

define business logic, utility functions, or other functionalities

that can be shared across multiple programs.


User Defined Data
Namespa
Type
ce
What You Can Write Inside ? Access Modifier Allowed
1. Class Inside ?

2. Struct 1. Internal

3. Interface 2. Public
4. Enum

Default Access Modifier for ? Namespace can’t have


modifiers
Default Access Modifier inside ? Internal is Default Access
User Defined Data
Type
Class
What You Can Write Inside ?

1. Attributes [Fields] => Member Variable


2. Functions [Constructor , Getter Setter , Method]
3. Properties [Full Property , Automatic Property , Indexer]
4. Events
User Defined Data
Type
Class
Access Modifier Allowed Inside?
1. Private
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public

Default Access Modifier inside Private


? is Default Access modifier
User Defined Data
Type
Struct
What You Can Write Inside ?

1. Attributes [Fields] => Member Variable


2. Functions [Constructor , Getter Setter , Method]
3. Properties [Full Property , Automatic Property , Indexer]
4. Events
User Defined Data
Type
Struct
Access Modifier Allowed Inside?
1. Private
2. Internal
3. Public

Default Access Private is Default Access modifier

Modifier?
User Defined Data
Type
Interface
What You Can Write Inside ?

1. Signature For Property => C# 7.0


2. Signature For Method => C# 7.0
3. Default Implemented Method => C# 8.0 Feature .Net Core 3.1
[2019] Modifier Allowed Inside?
Access
Interface members without an implementation might include an access modifier except
Private.
Members with a default implementation can include any access modifier.
Default Access Modifier for Internal
? Default Access Modifier Publi
User Defined Data
Type
Enum
What You Can Write Inside ?

Set of named constants [Labels]

Access Modifier Allowed Inside?

No Access Modifiers Allowed inside Enum

Default Access Modifier for ?

Internal
Access Modifiers
● They are keywords used to define the accessibility of types
(Ex: classes, structs, enums and Interfaces) and their members (Ex
: fields, properties, methods, etc.).

● These modifiers determine where the members or types can be


accessed inside the code
Access Modifiers
From Less Accessible To Wider

1. Private

2. Private Protected

3. Protected

4. Internal

5. Protected Internal

6. Public
Access Modifiers
1. Private
Accessibility: The member is only accessible within the class or struct it is defined in. It cannot be accessed from outside the

class.

Usage: Use for members that should only be accessible within the class, often for internal implementation details.
2. Internal
Accessibility: The member is accessible only within the same assembly . It is not accessible outside the project, even in derived

classes.

Usage: Use when you want the member to be accessible only within the same project/assembly, but not from other projects or

3. Public
libraries.
Accessibility: The member is accessible from anywhere in the application, both within the same assembly (project) and from other

assemblies.
Struct
● Struct is (stand for "structure") is a value type meaning That they are

stored on the stack like (int, char , double etc…) .

● As they are stored on stack that making them more lightweight for

small, short-lived data objects.

● They are commonly used to represent small, simple objects that do not

require inheritance or reference-type behavior


Struct
Characteristics of a
Struct :
● Constructor C# 9 [.net 05] : Structs cannot have an explicit parameterless constructor
before C#10 compiler provides a default constructor

● Constructor C# 10 [.net 06] : When struct haven’t an explicit parameterless constructor


(the compiler provides a default constructor that initializes all fields to their default
values).
If There is a user defined constructor it must initialize all attributes of struct
● Constructor C# 11 [.net 07] : User defined constructor can skip attribute of struct without
initialization
● Constructor : if user defined a user-defined constructor compiler will always provides a
default constructor
● No Inheritance: Structs cannot inherit from other structs or classes (except from
ValueType, which is implicitly inherited).
Struct
Point P1 ;
Declare for Variable|Object From Type Point
CLR Will Allocate 8 Uninitialized bytes at
stack
P1 = new Point();
new() with struct is used only for constructor selection

P1.X = 10; 8
X 10
0
Bytes
P1.Y = 20; Y 20
0

Stack
Struct
Point P1 = new Point() ;
X 100
10
P2 8
Point P2 = new Point(100 , 200); Bytes
Y 200
20
P2 = P1;
P1.X = 500;
X 10
500
Console.WriteLine(P1.x); // 500 P1 8
Y 20 Bytes
Console.WriteLine(P2.x); // 10
Stack
Struct
Summary
● Value Type Stored in Stack

● Support Encapsulation and Overloading in


Polymorphism
● Doesn’t Support Inheritance
● 3 Access Modifier Allowed Inside It [Public ,
Internal ,Private]
● Compiler Will always Generate Parameterless Constructor
That Initialize Struct attributes with Default value unless you
Defined a Parameterless Constructor
OOP Definition
● programming paradigm that is based on the concept of objects.
● OOP aims to structure software in a way that models real-world
entities and interactions, using OOP key concepts.

OOP Key Concepts |


Pillars :
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
OOP Definition
Encapsulation :
● It refers to the bundling of data (fields) and the methods
(functions) that operate on that data into a single unit or
class. It provide restricting access to some of an object's
internal state (Data) and requiring all interaction to be
performed through well-defined methods (Getter and Setter).

● This protects the internal data and ensures that it can only be
modified in a controlled way.
OOP Definition
Inheritance :
● It allows a class (called a derived class or child class) to

inherit members like properties, methods, fields and behaviors

from another class (called the base class or parent class).

● This allows code reuse, and the ability to create a hierarchical

relationship between classes


OOP Definition
Polymorphism :
The word polymorphism comes from Greek, meaning many
forms.
● Overloading

● Overriding
OOP Definition
Abstraction :
● It is the process of hiding the complex implementation details and only

exposing the necessary parts of an object or system to the user.

● It Allows us to define what an object does without needing to know how it

does it.
Encapsulation
Separate Data Definition [Attributes] From Its Use [Getter Setter ,

Property]
Encapsulation
Properties :

Property where you can define the get and set accessors with custom business logic,
1. make
Fullyou
Property
have more control over how values are retrieved or assigned

The C# compiler generates private backing fields for these properties behind the
2. Automatic Property
scenes

You might also like