OOP with derived or abstract classes, overrides | IEnumerable [Pt 19] | C# for Beginners
Vložit
- čas přidán 9. 11. 2023
- View full playlist: aka.ms/dotnet/beginnervideos/...
Set up C# in VS Code: aka.ms/dotnet/get-started/vscode
🏆Earn the C# Certification: aka.ms/csharp-certification
Let's dive deeper into Object Oriented Programming with our Person/Pet example. We currently have a Person class and a Pet Class. Scott and David build the blueprints to expand our Pet example with base classes, abstract classes, and derived classes.
Links:
.NET Beginner Videos: aka.ms/dotnetvideos
MS Learn: aka.ms/dotnet/beginnervideos/...
Blog: aka.ms/dotnet/blog
Twitter: aka.ms/dotnet/twitter
TikTok: aka.ms/dotnet/tiktok
Mastodon: aka.ms/dotnet/mastodon
LinkedIn: aka.ms/dotnet/linkedin
Facebook: aka.ms/dotnet/facebook
Docs: learn.microsoft.com/dotnet
Forums: aka.ms/dotnet/forums
🙋♀️Q&A: aka.ms/dotnet-qa
👨🎓Microsoft Learn: aka.ms/learndotnet
#dotnet #csharp - Věda a technologie
This is literally the best instructional video series on programming I have ever encountered. Please, for the love of all that is holy, keep making these videos!
Thanks for the positive energy! Had a great time with you mates. Personally, I find your pedagogical approach to be highly effective. I greatly appreciated the balance between the little jokes, the beginner-friendly mindset, and the valuable practical advice. I'm impatient to see you in the next C# modul!
please keep on going with more, thanks David and Scott !!!
C# has a very elegant syntax 💜
among most of the tutorial series in the channel , you guys were the best.
thanks for the videos.
This was great. You both have a gift for breaking things down. Objects and constructors finally make sense to me!
Coming from a functional language this has really helped me get my head around OOP and how its implemented in c#
Finished all , The way you two taught is awesome I just couldn't stop.
Thanks and All the best , Looking forward for more videos by you two.
Watched the full series. You are presenting it very well Scott and Fowler. Thank you very much.
Would be good to lead the learner onto next steps... Further courses or ms learn docs.
Great series, thanks guys
Great series. Informative and easy to digest. Thanks guys.
Great stuff, friends! Keep up the great work.
Thank you guys, learnt new styles/techniques here,, awesome stuff
Thank you for the playlist 💫💫
Wish you guys went all in for all the rest of C# features, really great content
Thank you for this wonderful intro. :)
Thank you David and scott
What would be the NEXT best playlist to watch after finishing "C# for Beginners"? I definitely learned a lot from those two awesome instructors.
This was a fun series, thanks for the videos!
Great series. Thanks!
That was terrific. Thank you for the effort.
I would really appreciate it if you suggested some follow-up projects to strengthen the knowledge and hopefully, help us learn more
I enjoyed this series
very helpful. please keep going😀
This series is great, i enjoyed it an learnt a lot from it. Please can we get more lessons. Anyone can definitely learn programming from you guys. Thank you
Awesome content
Thank so much.
Amazing
Very cool explanation. Using your example, how would you deal with pets that don't make noise (lizards, corn snakes etc)? Would those types of pets not have a MakeNoise method? Or would you use some other way of dealing with the question?
I saw your comment and tried to find an answer. I made it work by putting it like this : public override string MakeNoise() => null;
I'm kinda late but hope it may help
Please upload some more videos on advanced topics
since we can't create a Pet instance why is the constructor (string firstname) for?
According to the inheritance principle. First base class constructor will be called and it will initialize the firstname property to the name passed.
It's "Beyoncé"!
I think it would be more useful (in terms of learning), to use a concrete (real life) business case to solve. E.g. a real usable to-do list, or a notepad, or a calculator or whichever suitable application.
All this from A to Z (X-Y-Z being an advanced, with modern writing/refactoring videos). Also show what happens when not using good/best practices. E.g. show the exploit, show what happends in the real application. by doing this, i think people will understand the language better, and concepts behind it too. Instead of vague, non realistic, abstract use cases.
This is too abstract for me... :P
what is next ? which lesson we can take further ?
the lesson was difficult for me , I don't undertand why they made Pet list in the person class, they should made the dog list or can in person class ?
If you just created a list of dogs you could only ever add dogs, by creating a list of the base class you can create an object of any derived class in this case Cats or Dogs you cant create an instance called Pet because its abstract
I hope that helps this vid make sense. The List is a generic Type collection. Meaning if you made a list of Dog then only Dogs could go in the list. But since they made cat and dog derived from the pet class, dogs and cats can both be placed in the same generic list of pets. It’s the beauty of inheritance in OOP.
var me = new Person("Kevin", "Velez", 19);
me._pets.Add(new Dog("Bobby"));
me._pets.Add(new Dog("Toby"));
me._pets.Add(new Cat("Whiskers"));
me._pets.ForEach(pet => Console.WriteLine(pet));
public class Person(string name, string lastname, int age)
{
public string _name { get; set; }
public string _lastname { get; set; }
public int _age { get; set; }
public List _pets { get; set; } = new();
}
public abstract class Pet(string name)
{
public string _name { get; set; }
public abstract string MakeNoise();
public override string ToString() => $"{_name} is a {GetType().Name}";
}
public class Dog(string name) : Pet(name)
{
public override string MakeNoise() => "bark";
}
public class Cat(string name) : Pet(name)
{
public override string MakeNoise() => "meow";
}