oop concepts
TRANSCRIPT
OOP ProgrammingMelick R. Baranasooriyamelick-rajee.blogspot.com
Principles of OOP
Abstraction
Encapsulation Polymorphism
Inheritance
2
3
Inheritance
Loyalty
Member
Staff
Gold
RegularNon Member
4
Classes and Interfaces
Classes
Fields, properties, methods
Methods contain code for
execution
Interfaces
methods and properties, left to be implemented
later
5
Inheritance
characteristics of existing parent class
extend the parent class
Add new fields and methods
AttributesOperations
Redefine methods 6
Inheritance
inherits
implements Extends
Extensibility
Reusability
Provides abstraction
Eliminates redundant code 7
8
Accessibility Levels
protected internal - limited to the current assembly or types
derived from the containing class
Protected - limited to the containing type and types derived from it
Internal - limited to the current assembly
Private -restricted to the containing type
Public –access is not
restricted 9
Important Aspects
Instance and static constructors are not inherited
Multiple interfaces can be implemented
Structures cannot be inherited
No multiple inheritance
Transitive relationC < - B , B < -A
then C <-A 10
Demo
Sealed
Methods + New Multiple Interfaces
Virtual + Override
Access Modifiers11
Abstraction – Reducing the complexity
Classes defined with the keyword abstract
Implemented or fully unimplemented
Not implemented methods are
declared abstract
Class + Interface
Cannot be instantiated 12
13
Encapsulation
Hides the implementation details
All data members should be hidden
Accessed via properties
Public interface
No interface members should
be hidden 14
Encapsulation ..
Private data fields
Changing the class internals does not affect
Change fields validation
Constructors and Assessors
Reduces complexity
Easier maintenance
15
Polymorphism Cohesion and Coupling
Having many forms
Virtual Keyword
Override Keyword
Extensibility
Reusability
Provides abstraction
Eliminates redundant code 16
17
THANK YOU! 18