Advantages of Interfaces
Functionality is defined but not
implemented; so definition is separated by implementation.
You can define a
single implementation which can define multiple interfaces
(Interfaces of C#
are provided as a replacement of multiple inheritance)
Interfaces are better
in situations in which you do not need to inherit implementation from a base
class
Structures cannot inherit classes but they can implement
interfaces.
(So, this is useful when you can’t use inheritance)
Data
hiding
Easy to develop by a team
Interfaces are a logical way of grouping
objects according to the functionality/behavior
Enhances abstraction
Advantages of Inheritance
Derived classes and base class can be used
interchangeably.
Derived classes can extend base class’s functionality with
specific methods.
(Base class should leave the specific method implementation
to derived classes so that any kind of enhancement/extension is
possible)
Code can move from general purpose classes to very specific classes
by adding additional functionality at the each level.
Ability to make changes
to the base class that will appear in all derived classes
Data hiding (Base
class can keep some members private so that they cannot be altered by derived
classes)
Advantages of partial classes
It separates the
designer generated code (in UI) from business logic.
Team can develop the
code as separate blocks. (Multiple developers can work simultaneously)
Easy
to differentiate the automatically generated code and user implemented
code.
All the sections of the code will combine at the compile
time.
Improves code readability
Advantages of generics in .NET 2.0
at the compile time rather than throwing an exception in the
runtime.)
Improves performance – Generics do not require boxing and unboxing
as opposed to ‘object’ type.
Type safety
Avoid code duplication
You can
use constraints in case you want to go beyond the capabilities of the Object
class.
Advantages of delegates
Encapsulates a method with a specific signature
Provides an
object-oriented, more secure functionality of a function pointers in
C++
Allow decoupling between the event sender and event receiver.
When an
event occurs we can call one or more functions simultaneously
No comments:
Post a Comment