From 1137d1b922b4e95cf3b3f77361f913f08c172707 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 22 Feb 2021 22:58:49 +1100 Subject: [PATCH] Finished Chaining Constructors --- csharp_fundamentals/8_oop.md | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 csharp_fundamentals/8_oop.md 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