Slot 04 - 05 Object Oriented Programming
Slot 04 - 05 Object Oriented Programming
Object-Oriented Programming
Lession 3
2
Objectives
▪ Using declarations
▪ Expression-bodied members
▪ Record type
▪ Object Initialize
▪ Read-only auto-properties and Init-Only Properties
OOP Paradigm
Procedure-Oriented Program
Class A
{
data1
data1
data2 Modifiers Function1 ()
Function1 (data1)
Function2 ()
Function2 (data1) }
Function3 (data2)
Function4 (data2)
Class B
{
data2
Object = Data + Methods
Modifiers Function3 ()
An object can inherit the properties of another object using the concept
of inheritance. Hence, we can say that object-oriented programming is
organized around data and the operations that are permitted on the
data
Member Visibility
◆ There are five access specifiers: private, public, protected, internal, and
protected internal. By default, the members are private to the class
▪ public: The type or member can be accessed by any other code in the same assembly or
another assembly that references it
▪ private: The type or member can be accessed only by code in the same class or struct
▪ protected: The type or member can be accessed only by code in the same class, or in a class
that is derived from that class
OOP-Encapsulation
◆ When we write a property only with "get", it automatically becomes a Read Only
property or we can use Init-Only properties
OOP-Inheritance
OOP-Inheritance
OOP-Polymorphism
OOP-Interface
OOP-Interface
Interface Inheritance
The is operator returns true if the given object is of the same type whereas as
operator returns the object when they are compatible with the given type
The is operator returns false if the given object is not of the same type
whereas as operator return null if the conversion is not possible
The is operator is used for only reference, boxing, and unboxing conversions
whereas as operator is used only for nullable, reference and boxing
conversions
Static Constructor
Static Class
No instance created
Extension Method
Extension Method
Expression-bodied Members
Expression-bodied Members
Anonymous Type
Object Initialize
Record type
◆ Records type is a new reference type that we can create instead of classes or
structs
◆ Records are distinct from classes in that record types use value-based equality
◆ We define a record by declaring a type with the record keyword
Record type
Using Declarations
◆ With the using declaration, the objects are disposed automatically. Its scope is
automatically defined from the object’s declaration statement to the end of the
current code block
▪ Using declarations
▪ Expression-bodied members
▪ Record type
▪ Object Initialize
▪ Read-only auto-properties and Init-Only Properties