You are on page 1of 6

#Vision2025

Session:14
www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

• Encapsulation Using Accessers and mutators,Encapusulation using


properties

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Encapsulation:

• Encapsulation is the procedure of covering up of data and functions


into a single unit. An encapsulated object is often called an abstract
data type.

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

We need of Encapsulation for the following reasons:

• One of the fundamental principles of object-oriented programming.


• A process of hiding all the internal details of an object from the outside world.
• Provides a way to protect data from accidental corruption.
• Gives the ability to validate the values before the object user change or obtain the value.
• Makes implementation inaccessible to other parts of the program and protect from
whatever actions might be taken outside the function or class.

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Encapsulation using Properties:

• Write-Only Property: Properties can be made write-only. This is


accomplished by having only a set mutator in the property implementation.
• Creating Read-Only Fields: Properties can be made read-only. This is
accomplished by having only get accessor in property implementation.
• “static” property: C# also supports “static” properties. The static members
are accessed at the class level, not from an instance (object) of that class.
Static properties are manipulated in the same manner as static methods, as
www.cambridge.edu.in
seen here:

www.cambridge.edu.in
#Vision2025

END
www.cambridge.edu.in

www.cambridge.edu.in

You might also like