diff --git a/csharp_fundamentals/8_oop.md b/csharp_fundamentals/8_oop.md new file mode 100644 index 0000000..b472510 --- /dev/null +++ b/csharp_fundamentals/8_oop.md @@ -0,0 +1,57 @@ +# Module 8. Object-oriented Programming with C# + +## The Pillars of OOP + +3 pillars +* **Encapsulation**: hide details. + * Methods; Properties; Access modifiers; +* **Inheritence**: Reuse code +* **Polymorphism**: Have object behave differently + +## Deriving from a Base Class + +Reference: +* [Inheritance in C#](https://dotnettutorials.net/lesson/inheritance-c-sharp/) +* [Inheritance in C# and .NET (C# guide)](https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/inheritance) + +Syntax: + +```csharp +public class ChildClass : ParentClass +{ + //... +} +``` + +## Chaining Constructions + +Reference: +* [Call Chain of Constructors in C#](https://app.pluralsight.com/guides/call-chain-constructors-csharp) + +When constructor of parent class has parameter, we can chain the constructor of child class using `base(param1, ...)` + +Syntax: + +```csharp + public class ParentClass + { + + public ParentClass(string name) + { + Name = name; + } + public string Name + { + get; + set; + } + } + + public class ChildClass : ParentClass + { + public ChildClass(string name) : base(name) + { + Name = name; + } + } +``` \ No newline at end of file