Reworded and added to csharp interface documentation (#33229)
* Reworded and added to interface documentation Fixed a few typos and reworded and added parts to the csharp interface documentation * fix: used single backticks instead of triple backticks
This commit is contained in:
committed by
Randell Dawson
parent
eaf1c56e16
commit
20cf0d106c
@ -3,12 +3,12 @@ title: Interface
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
An interface is similar to a class or struct but without implementation for its members.
|
An interface is similar to a class or struct but without implementation for its members.
|
||||||
An interface declares a contract or a behavior that implementing classes should have.
|
An interface declares a contract or a behavior that implementing classes require.
|
||||||
It may declare only properties, methods and events with NO access modifiers.
|
It may declare only properties, methods and events with NO access modifiers.
|
||||||
|
|
||||||
All the declared members must be implemented in the inharit class, otherwise will have an compile error.
|
All the declared members must be implemented in the inherited class, otherwise you will have a compile-time error.
|
||||||
as a convention we will mark interface with the letter I at the begenning (IMyInterface || IUserOptions).
|
The convention is to start the name of the interface with the letter I, such as `IMyInterface` or `IUserOptions`.
|
||||||
You define an interface by using the interface keyword.
|
You define an interface by using the `interface` keyword.
|
||||||
|
|
||||||
All members of an interface are:
|
All members of an interface are:
|
||||||
implicitly abstract,
|
implicitly abstract,
|
||||||
@ -19,14 +19,14 @@ An Interface can:
|
|||||||
* Inherit from multiple interfaces at the same time
|
* Inherit from multiple interfaces at the same time
|
||||||
* Contain only methods, properties, events, and indexers.
|
* Contain only methods, properties, events, and indexers.
|
||||||
|
|
||||||
An Interface can not :
|
An Interface can not:
|
||||||
* Inherit from a class.
|
* Inherit from a class.
|
||||||
* Have implementation.
|
* Have implementation.
|
||||||
* Have access modifiers other than public.
|
* Have access modifiers other than public.
|
||||||
* Be instantiated.
|
* Be instantiated.
|
||||||
---
|
---
|
||||||
|
|
||||||
Using interfaces allows us to change our implementation in our project without breaking other parts, and only have to change the one place where the object is created.
|
Using interfaces allows you to change your implementation in our project without breaking other parts. You only have to change the one place where the object is created. Interfaces also ensure that any new members added to the interface are implimented in all derived classes by throwing errors at compile time.
|
||||||
|
|
||||||
As interfaces do not implement any logic by themselves, they are a great tool for programmers to program against a type rather than a concrete object. This is very useful in keeping code loosely coupled. This behavior of interfaces made them imperative for implementation of Design Patterns.
|
As interfaces do not implement any logic by themselves, they are a great tool for programmers to program against a type rather than a concrete object. This is very useful in keeping code loosely coupled. This behavior of interfaces made them imperative for implementation of Design Patterns.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user