Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>



									Benefits of Object-Oriented Programming?
Structured Design Tendencies Object-Oriented Tendencies

1 2 3 4 5


Reveals Data

Hides Data

Single Unit

Modular Units

One-Time Use Ordered Algorithm

Reusable Nonordered Algorithm

Understanding Programming Concepts (Component Based)

Accessibility and Scope
• Access modifiers are used to define the accessibility level of class members
public private internal protected protected internal

Access not limited. It can be used in the current and other assemblies. Access limited to the containing class i.e. to all the statements of current class. Access limited to the current assembly only. Not accessible to other assemblies. Access limited to the containing class and to types derived from the containing class Access limited to the containing class, derived classes, or to members of this program

What Is Encapsulation?
• Hiding internal details
– Makes your object easy to use

• Grouping related pieces of information and processes into self-contained unit
– Makes it easy to change the way things work under the cover without changing the way users interact – Properties in C#(Component Based) Programming provide encapsulation.

What Is Inheritance?
• Inheritance specifies an is-a-kind-of relationship (UML) • Derived classes inherit properties and methods from a base class, allowing code reuse • Derived classes become more specialized
Base Class Bank Account



Derived Classes

How to Create a Derived Class



How to Create a Derived Class
" # # & $ $ %

& # $ $ %

& ''' " # $ (

$ ( '


" # *+,-./01 -22222'02

How to Use a Sealed Class
• You cannot derive from a sealed class • Prevents the class from being overridden or extended by third parties

(3& 44

Abstract Classes and Methods?
An abstract class is a generic base class
– Contains an abstract method that must be implemented by a derived class

• An abstract method has no implementation in the base class • Can contain non-abstract members
5 & 3 " 3


What Is Polymorphism?
Employee Objects RegularEmp Method Called Behavior
Salary for Regular Emp

CalcSal ()


CalcSal ()

Salary for Hourly Paid Emp


CalcSal ()

Salary for Contracted Emp

How to Write Virtual Methods
• Virtual methods are used to define base # class methods that you expect to be & ' 6 75 overridden in derived classes Base Class Derived Class
Animal Virtual Method Eat () Cat Override Method



& What Happens '
Eat Something

# 6 75 What Happens
Eat Mouse

Eat ()


How to Use Base Class Members from a Derived Class
• The base keyword is used to call a method in the base class from a derived class
& # '5 & 7 ' 6 75 8 # 5

To top