All right.
You do it like in the old days.
And my cool.
Good evening everyone.
No. Welcome to master class.
This evening we have Jordan Mendes.
To.
Teach.
He's gonna be in love. I don't know if anybody remembers that
as far back as I do, I remember there was a guy who used to read
books. He was real old.
Yeah, I remember that. I don't remember his name, but yeah.
On TV.
I can't remember.
Yeah.
You're aging yourself.
Did well.
I know I am. I was very little.
Yeah.
There's actually, there's actually a website that you can
I was very young.
go on and they say if you have an attractive enough voice, you
can actually read books, audio books, record it, and they'll
pay you for it.
That's what I need to do and do that on the side. See you. I
Wow, I need to yes.
wanna do that. Yeah. OK. So yes. Welcome, everybody. I think
you're gonna really enjoy this. Evening. Jordan Mendes has a
wonderful topic for us tonight.
Very informative and educative.
Ah, jeez, forget it. It's too late for me to have correct
words, and I have to teach after this. So Jordan, it is yours if
you want to go ahead and share the screen.
And you can get started.
All right, let's do it. Now. This is gonna be weird here.
I'm actually just gonna share it like this because I'm gonna be
closing and opening this up a bunch of times, so it's gonna be
a real pain to kind of reset it each time.
So I'm just gonna read it like this. So this topic we got OOP
fundamentals.
But we're actually not gonna use the slide show as much. I made
it for this master class. And where could use the information
off of it. But I'm actually just gonna do a live coding demo. I
felt like that would be more beneficial for everybody. And
you can actually see how everything works. I know loop is
a huge topic, pretty much if you even want to consider software
development or any kind of programming language as a
career. Poop is something that you pretty much have to learn.
You have to know about. You have to understand. So.
I decided that I'd probably be a really good topic for majority
of people in the internship.
So oops, alright, so we'll go to what is OOP. Oop stands for.
Object Oriented programming consists of three main pillars
as encapsulation, inheritance and polymorphism. That is also
abstraction. Some people consider that a pillar of OOP.
Some people don't. I tend to not really think of it as a pillar
of OOP, mainly because it's a mix of a class in an interface,
but it kind of behaves as something that you would really
want to incorporate in when you're doing.
Object oriented programming, but when it's used correctly, object
Orient programming can make a program loosely coupled and
highly flexible and meet the needs of the stakeholders. So
basically.
If you do it right.
You can allow your program continue to keep expanding
without having to constantly go back and fix things and adjust
things.
So the first pillar, MOOP. We're gonna look at is encapsulation.
So what is encapsulation?
Capsulation is the idea of keeping data and behavior hidden
that is not necessary for the user to see.
That doesn't make much sense and the coding demo might not even
make much sense because it's a weird concept to kind of grab,
but hopefully by the time I'm done coding it and explaining
it, it will make a lot more sense.
This is achieved by use of access modifiers when declaring
variables within a program.
There's different types of access modifiers.
Two of them. I'm gonna demonstrate inside of this demo
for the sake of time, but there's five main ones you have
public, which is access to all the code in the program. So
basically anywhere within your entire solution, you'll be able
to access those files.
Or that class or that method?
Then you have private.
Access to only the members of the same class. So if you have
something that's private, it's only available to see within the
scope of that class that you're using and.
This might not all make a lot of sense about explain it once we
start actually coding here right after the slide.
Yet protected.
That gives you access to members of the same class and it's
derived classes.
So basically, if you have something that's protected.
Anything that's made within that class, you can see it if it's
labeled as protected or anything that if you inherit off that
class, if you make a child class off of that class.
Or derived class that is also available to see if something is
labeled as protected.
And you have internal.
Which gives you access to the current assembly or project
solution. So sometimes in really large scale applications you'll
have multiple solutions. You'll have multiple different as I
guess you could say and look at it as like multiple coding Ides
right? Cuz typically most people when they're creating a project,
they're on a single ID and you have a single solution on there.
Most people aren't involving multiple solutions until you get
to a full scale.
Company project so.
I guess for sake of terms.
You'll consider that as a solution, so here.
This is a solution I have. The solution master class live demo.
OK, that is the solution.
And then right here you have protected internal which gives
you access to the current project solution and its derived
types from the same class. So.
That one is a weird one. You will probably not see that one
very often if that at all within your career as a software
developer or programmer. It's just not common.
Protected. You may see every now and then, even internally you
might not see the most common ones you'll see are public and
private, and those are the ones I'm actually go over today. I'm
not even gonna address. These are the three because it's just
something that you won't really see as much in your career,
maybe protected, but even then still.
Alright, so we're gonna just hop right into coding here.
Alright, so here I just set up some stuff here, so I got some
comments. I'm just talking about each topic. Wanna talk about
encapsulation heritance. I'm talk about abstraction.
Talk about polymorphism and then I got two bonus.
Parts here method overloading and empty construction creation.
Within a class.
OK.
So let's talk about an capsulation.
So I guess to talk about encapsulation, we first have to
make a few classes and I guess we'll make one public and one of
them private. So you can kind of see, I'm sorry, we'll make both
of them public so you can see how they kind of work here. So
let's start by making a class.
So go ahead and here, add class and we're gonna name this one
encapsulation.
Right now we have a.
Class here or change this to public.
So here we have a public class encapsulation.
Alright. And we're gonna give it two methods. So we're gonna do
public void because it doesn't. It's not gonna return anything.
We're just gonna print directly to the console and this
application so we can see what's going on. So public void, and
we're gonna say.
You know, public message.
Not going to take any parameters.
And we're just going to say this is a public.
Message.
OK.
Where do the same thing again?
Public void where you say this one a private. I'm sorry. This
is gonna be private void.
Private void. And we're gonna say this one's gonna be a
private message.
This.
Is a private.
Message.
OK, so now.
By going off my definition and explained earlier how public you
can access things anywhere in the program, I should be able to
access this class and I should be able to access this method
here. So when I come here.
To my program and I create a new instance of the class
encapsulation. I should be able to access public message.
However.
Private means it's only available from the scope of the
course. Ohh scope of the class. So what does the scope the scope
are these little brackets?
Here.
So private. So that means that basically this right here only
lives within this scope here.
If I came out here and I tried to try to say, you know.
A private message. It doesn't pop up.
Doesn't even doesn't even wanna pop up for me.
So.
These methods only live within the scope of the course here,
and this is only available to anything within the scope. I
could come here and say let's do private message.
Why don't you actually gonna look constructor here? I mean
another method.
The message.
And I could say console rate line.
And I'm gonna say.
Just get private message.
So here.
I just accessed.
This.
This right here I just accessed this.
Method.
Right here, inside the scope of the course. But if I came out
here.
And I tried to do let's create a new instance of this class here
encapsulation and capsulation. Basically I'm saying I'm calling
the class name encapsulation. That's it's type I'm giving you
the name encapsulation and I'm saying it could be a new version
of that class, encapsulation. That's basically what I'm saying
here.
And we're saying encapsulation public message.
OK.
Let's call it this out because it's a good yell at me.
And so now I can access if I run this program.
This is a public message right there, OK.
Let's try accessing that private message.
Doesn't even pop up at all. I can I can try to force it.
Yelling at me.
See it's inaccessible due to its protection level. I wrote that
out and it's yelling at me because it knows I'm trying to
force.
Getting information from somewhere that I shouldn't be
getting it from.
But if you don't even know that's air doesn't pop up for
you, I can do public message again and it pops right up in my
Intellisense.
A private message doesn't at all. I could screw on this whole
list. It's not going to be there.
But if we go here, there it is.
So.
Let me come over here on my other demo here.
So what would you use this for then? What? What? What's the
purpose of this? If you can't even access that? That logic
here.
Well, let's say this logic did something for us, right? So
let's give this Class A property we're going in, and we're gonna
say number, OK?
So this property is gonna store number. We don't know what the
number is. We have no idea what the number is, but we're gonna
get that number.
Where to get it with the use of a public?
Method here.
So public method.
Actually I got I got a return it in here.
Actually, no, I shouldn't have to. I should be fine. Public
void get number.
OK.
And what I'm going to do.
Because I'm actually get rid of this private message here.
And I am going to set a number right here, so who knows? I can
set a number and I'm gonna say it's gonna be equal to, I don't
know, 15, OK.
Now on the outside world, I have no idea what this number is
gonna be.
But I can get it right here. So if I do.
You know console out write line print number.
Right.
So now if I come here, I do encapsulation dot get number.
And I run this program.
I got zero. I did it. Get zero. That's interesting. Should have
gotten 0.
By the Ant.
Why did you get problem? Why did you get that?
Oh, I know why.
I know why.
Because I need to make a constructor.
OK.
So now if I run this.
15.
Alright. Mind you, I'd even talk to this class at all out here.
All I did was say get me in my number and I called this method
and it said OK. You're gonna get the number here that's stored
here, which it got from here.
Private methods are good inside of a class to.
Take logic, do the logic and not let somebody know how you do the
logic. Don't at the program doesn't have to know how you do
the logic, you just need to get that logic that's in that
method. That's it. This is a good example. Do when you're
like password hashing or you're dealing with sensitive
information. That's when this really shines.
What we did here and the reason I got zero the first time was
cause.
When you first create a class.
There's these things called constructors, and we'll talk a
little bit more about them later on. But a constructor basically
is a block of code that is going to run.
And execute when you call a class.
OK, so basically I'm here.
I said encapsulation dot get number so my program came over
here.
And it ran this block of code right here. And I said OK First
things first. I'm going to run this code.
Come in here. I'm gonna call. Private message came here and
said OK, number is gonna be equal to 15. Done.
OK, I'm done with this now. What did I come here for? Ohh. I came
here to get the number and now I'm saying. Oh, alright, we're.
Where is this number located? Oh, it's OK here. And that's
already set to 15.
Alright, and let's set a break point so we can actually see
that in live time here. So here we have a break point.
So we're to get the public message. So let's step into this
method. So here this little arrow is showing me where the
code is, where the program is at each step here.
So it's gonna say, OK, I gotta get the public message.
OK encapsulation. Public message here. Target 15.
And number OK, so now it's going to get the number number is 15
done.
It just went in there, did all that code for me and stepped
through. I stepped through the entire class there.
That's kind of how a constructor works. We'll talk more about
that later on.
But this is how you would set up to to make sure you can access
those private methods there.
Umm.
That's pretty much encapsulation in a nutshell.
When you are, let me take this break point off here. When you
are dealing with sensitive information, you wanna hide that
information, you throw access modifiers on them to prevent
people from being with access to that information anywhere within
the program. OK.
And then from there you can go ahead and you can set those
private informations to fields or properties within that class
to still be able to get your information, but you just don't
know the logic behind getting that information out and that's
fine. You don't need to. That's how encapsulation is supposed to
work.
So with that being said, we'll move on to inheritance.
Heritance is, let's jump over to my PowerPoint again.
Second pillar of OOP is inheritance. Inheritance is the
idea of inheriting properties and methods of another class,
thus called inheritance.
And good practice inheritance should share logic and be a is a
relationship. A dog is an animal. A car is a vehicle.
OK.
If you're not careful, we can very well easily work yourself
into a corner with inheritance.
And we're going to see a little bit about that kind of quickly.
But we're gonna see a little bit how you can work yourself in a
corner in the demo. I'm gonna do.
The class that is inheriting.
It's called the child class or a derived class.
And then the class that is inherited from is called the
parent class or the base class.
Constructors are not inherited from a base class.
And inheritance is initiated by following the same class name.
The colon followed by the inherited class. So here we have
a class game of cat and it's inheriting the class of animal.
So basically cat is gonna get everything that's inside of
animal. Is pretty much what's going up happening and we're
gonna see how it works right now.
OK.
So let's start where actually use the animal example here. So
let's start by creating a new class called Animal. So let's go
ahead and add a new class in. We're going to call this animal.
Alright, we're going to change this to public.
Usually doesn't have that access modifier, but because it's a
console app, it will.
Alright. And let's see, we're gonna do.
Uh, we're gonna set some properties here that are
normally found within an animal. OK, so we're just gonna say
string and animal walks, right?
And animal eats.
And then in animal.
Let's see what else sleeps OK.
So there we got three properties, very simple
properties. I'm gonna make a constructor.
Again, this is what's going to run. It's going set all these
values for me.
Before we even get inside this class.
Typically you could pass these values in if you're talking
about object or your programming, you could set these
individually to what you want it to do, but because this is a
demo, I just wanna set a value there so the program can run
basically.
So I'm gonna set walk to walk.
As we got, we're expecting a string back here. Edu is gonna
equal to eat.
And sleep is gonna be, of course sleep.
OK.
So now.
We'll go back to program.
Alright. And let's call an instance of that class animal.
So animal animal.
Is equal to new animal OK.
Again, call in that class name, giving it a name, and this this
name right here doesn't matter. I can name this AI can name this
anything. Actually, I will name it a.
Just for short of animal, typically it's good to name it
something similar to whatever the class name is, but just it
for demonstration sake I will name it to something totally
irrelevant.
Just to prove that it doesn't matter what anyone is. OK, so
let's see. I'm gonna do a console rate line.
And I want to print out those.
Values there somebody to use some string interpolation. I'm
gonna say animals can.
And I'm going to call on that a class, and I'm going to call on
the walk method here.
OK. And I'm gonna do this for the other two.
And except this one going to sleep and this one gonna say
eat.
OK. But those of you don't know how string interpolation works.
You can actually go ahead and put in if you're going to be
passing values into your sentences, you can type your
sentence out normally with string interpolation.
You put a little dollar sign here in front of your sentence,
and then as you start typing, when you put an open and close
bracket, you can actually pass in a value, either a variable, a
class property, whatever you want. You can pass it in there
and what it'll do is it will actually put it in place of that
sentence and place it in that sentence. So when we run the
program here.
Uh, let me actually get rid of this too, so we can separate our
code a little bit.
OK, so when we run this program here, we'll run it.
Animals can walk, can't sleep, can eat.
Right.
Cool.
So let's see how inheritance works now. So we're gonna create
another class, and. Well, what can we inherit off of animal?
Uh, we'll use human, OK, because humans are animals. Why not,
right?
Let's create a new class called Human.
Public.
And I could leave internal on this, by the way, and it would
totally work just fine. I keep erasing public cause it's just a
practice of mine, but you can leave internal because it's all
within the same solution, so I wouldn't have to worry about
changing because this is all everything right here in master
class live demo. Everything below this little purple thing.
All this in here is all one solution so I could leave that
internal and will totally work.
Alright, so anyway, we're gonna go ahead. We're going to create
this new class human, right. And let's go ahead and inherit
animal.
All right, there. Boom. Done. We inherited animal. All set.
Just set one more property because what can humans do that
no other animal can talk?
Right.
So we're going to put in talk.
Of course, we need to set something to that value, so
we're going to say talk is equal to talk.
All right, that's it done.
Now you're gonna see the magic here. So mind you, human only
has talking inside of it, right? But we inherited animal. So
let's see what happens.
Human, human it's equal to new human.
Human whoops, I could spell it.
You end up. Oh, what's this? I got walk. I got eaten, I got
talk, and I got sleep.
Why? Because I inherited animal, so it gave me all this for free
right out of the gate. Gave me all that that animal has. Plus
what I made here, that is inheritance.
OK.
Again, it has to be an is a relationship.
OK. And sometimes you have to be very vague with is a
relationship, you can't say, well, animals do all these
things on what to throw all of them inside of a class because
you should really prepare for certain things like.
I don't know.
If you have a fish, a fish is an animal.
But do they walk know they swim?
So that's where you start working yourself in a corner.
But we're gonna continue on with this, and I'm gonna show you how
this all kind of works here.
Umm, so we're gonna do some more string interpolation.
OK.
And instead, we're going to do human.
Umm, I'll show you guys a little shortcut here. So in Visual
Studio if you hold down your shift button.
You highlight that tab and you held on your alt at the same
time. You can actually change all these.
At the same exact time.
Gives you a little shortcut there.
Sleep.
Eat.
Talk.
Run the code.
Oh wait, I didn't change this to humans. Whoops.
Humans.
And you know, just for the heck of it, I am going to go ahead
and put in some line breaks here just to give us some space,
clean up the code a little bit.
OK, animals can walk, sleep, eat. Humans can walk, sleep, eat
and talk. Umm.
Again, we inherited that animal class. We only have talk here as
a property, right?
I'll see you one more time. Let's see what we'll do. You
know, this is kind of already kind of gave out the answer here
about how I can work yourself into a corner, but we're just.
Go ahead and see it in live action, right?
Create a class called Dolphin.
Dalvin, alright, I'm actually leaving internal here. I'll show
you that will work.
Umm alright, so Dolphin is an animal, is it not?
Done.
OK. And what can dolphins do? They can swim.
Swim.
And you know what else they have? They have. So in our. So
we're gonna say Boolean, which is a true false value and it has
sonar or echolocation if you want to call it.
Instructor.
Swim is equal to swim.
And has sonar is equal to.
True.
OK.
Again, I'm using this constructor here. This code gets
called and we're gonna see that more later on in this in this
presentation.
This code gets called when the class is initiated here at
runtime so.
When the when the compiler runs and all these classes are
generated, all this code is pretty much ready determined
here.
So.
Here, let's go back over here and we're just go ahead and make
a new instance. I class. I'm going and make a new space here.
Just give us some room. Say, dolphin.
Dolphin is equal to new dolphin.
And we're gonna do the same thing we did here.
However.
And just all the dolphin again, shift over. Hold down Alt with
shift at the same time. Hit up on the keyboard and we can
switch it all at the same time. Hit escape to close that out.
Again, same exact idea or I switch this all at the same
time.
Only problem with doing something like this where you're
changing all these at the same time is Intellisense does not
like it, so you have to be sure of what you're typing. You can't
say ohh I think it's spelled like this because you'll run
into a bunch of errors if you do it one at a time. Intellisense
will work for you.
Otherwise it what? So right out of the gate?
Eat.
Park.
Swim.
Oh, we know dolphins can't talk, right? And you know they can't
walk.
We're not. We don't have that one here. So that was yelling at
me because that property belongs only to talk for the human
class. We didn't inherit human class it we herited the animal
class so essentially.
Right. Here's our animal class.
And then we have dolphin and we have human. So these two are the
child class of.
If I can get it back here of animal.
These two are the child class of animal. You have animal that's
base class. Human is inheriting animal. Dolphin is inheriting
animal.
OK.
So let's run this program.
Dolphins can walk, but we know that's not true.
Dolphins can sleep. Dolphins can eat, dolphins can true. Why is
that true?
Oh wait, that's cause a sentence. I have it, but that
should be true. Dolphins can swim.
They should say dolphins have.
Taps on archery. That's what I should say. That was nothing
wrong with the code. That was just me.
Not watching my sentences here.
So you say? Well, crap, how do I get a fix this now? Because I I
needed to open class but.
You know, animal has it. Well, what if I just take it out?
Animal. No big deal. Alright, so I'll just get rid of this. Not a
big deal. I'll get rid of that and I'll get rid of that. Done.
Easy fix, right?
Well, let's go ahead and save this. What do we got here? Now
we got error. We have error and we have an error.
Why?
Because you inherited from the animal class that walk property
that we just deleted, right? So let's put that back actually.
We're just get a commented out instead. That way we could still
see it.
So you inherited from animal class this walk property.
That's being assigned walk.
Into human.
And entered dolphin.
So now wherever that walk property was called because you
just deleted it, you just broke your code and three different
spots. By changing it in one spot. This is where inheritance
become a problem. And this is a small scale example. But when
you have a large problem or a large project and you do
something like that, you could break your code in 100 places
and it will take you forever to figure it all out.
When you use inheritance.
Over excessively, you can really make your application tightly
coupled and this right here is tightly coupled because we just
seen it. We changed one line of code and a broken in three
different spots.
That's that's an example of a tightly coupled application
right there.
Now if you guys remember my last week's presentation for master
Class, I went over and hired. I mean, I went over interfaces,
interfaces would be the solution to something like this, where
instead of inheriting walk you can give it the interface and a
class with the interface of that class and have a walk property
set to it.
That would be a better solution than to go ahead and rely on on
heritance.
And again, while animals can walk us through and humans can
walk us true, and a dolphin is an animal, sometimes you have to
be very broad. For me, I would say an animal can sleep and eat.
That's it.
I wouldn't even. I wouldn't even put like, breathe or anything
like that because of fish doesn't breathe there. But it's
an animal.
You know fish filters water through its gills and gets the
oxygen through the water.
Humans, I mean, I've dolphins don't walk.
So that's how inheritance can be working yourself into a corner,
but you could see how it worked here. We were literally pulling
code from other classes just by inheriting it, which is pretty
cool.
Alright, so on to abstraction now these other these other
examples will be a little bit quicker now because it's not as
much here, so I already have it.
Here.
OK, eggs abstraction. What is abstraction?
Basically, abstraction is the idea of hiding information
different from encapsulation.
And presenting only the required information to the user, hiding
everything else. It's a blend of a base class and an interface.
Let's see how it's done.
All right, so quickly we're going to create a class called.
Umm, we're gonna we're gonna create a class. That's good
dual. If they database right so.
Microsoft.
What the heck is this thing called here?
MSSM, always forget MSM, alright?
Uh, how much say DB, OK.
Set Microsoft SQL Manager database alright and let's give
it some properties here. Let me see what I set over here. I did
a save data so a public.
Boyd save data.
OK, this is gonna save data to a database. We're not gonna
actually hook up a database cuz we just don't have time for that
right this minute. So we're gonna say saves the data.
OK. And then another one public void get data?
And we'll say console write line UM gets the data.
Umm. And we're, you know, we're gonna do another one. We're
gonna do public void get connection string.
Your connection string is going to be basically a string that is
going to give you the connection.
It I guess to the credentials for like a basic.
Umm. For lack of, you know example.
But it will give you the credentials to talk back and
forth to your to your database basically.
So we have these right here, right get connect string so
that's cool. Find it Andy, right. So let's go ahead and
make that class.
Mrs OK. Yeah, yeah, yeah, we'll just called B and is equal to
new.
Alright.
Perfect. And we're just gonna go on DB and we're gonna have the
get connection string, right? We have the DB.
Uh, get data, right?
And we'll have the DB save data.
That was the three properties we just we just made there, OK, so
once you get the connection string.
Where to get the data? And we're gonna save the data, right? So
very simple example here.
Alright. And we'll make one more class and we'll say Azure.
Database.
Right.
As the word DB.
We'll call it, OK.
And same idea. We're gonna do a property. I'm sorry. Not a
property. We're gonna do a a method.
Method void. Uh get connection.
String.
And control rate line gets the connection sharing. I think is
what I said.
Gets a connection string.
OK. And we're gonna make another one here. Same idea. Where to do
a save data.
Saves the data and public.
Boyd, get data.
Gets the data OK so.
Most likely if this was a real situation this would be set up
totally different to begin with, but save data and get data would
be totally different than what this get data and save data
would be because it's you're talking to a whole different
server. It's not the same database you're talking to a
different one. Could you stored procedures and the other one
could use. I don't know entity or something but.
It it could be, it would be a totally different get and save
data. However, the connection string might very well be the
same as a very good chance it would be the same so.
What are we going to do? So where we're repeating code and
you hear of dry, don't repeat yourself. We're literally
repeating ourselves right here in two separate courses, have
two separate classes.
So how do we?
Get out of that. How do we? How do we prevent that, right?
So what we can do is we can make do inheritance and this is where
inheritance is really nice. We can make a new one and new
class, right?
And we are going to name it.
What?
Let's see. What are we doing here? We're gonna name it. Get
connection string.
Get.
Considering that's what I call it.
Easier. OK. And this is gonna have one method and that is it.
And it's gonna say get.
Connection string OK.
Now get connection string console right line gets the
connection string.
OK, so now.
We have our base class here we just made instead of repeating
ourselves and here and here, we're just gonna go ahead and
inherit.
Get connection string.
One spot.
And.
Get connection string two spots.
And before I go ahead and do that, let me before I delete
anything, I'll say zodb quals, new DB and Azure BD get
connection string. We have it there, get data, save data,
right.
Now.
We have the three properties and Azure and we have three
properties and the SSM DB, right?
We're inheriting the connection string.
So we don't need this no more. Get rid of that, right?
Don't need it.
Trash.
By because we're getting it right here already. Same exact
thing. We're inheriting this.
Getting it here and here.
And oh, did I delete the wrong one? Ohh I think I did.
Yeah, I did.
Whoops.
Public void get data.
That's why it's good to keep your code organized, because I
had mine in two different spots I had thought was same thing.
Gets the data.
Alright, let's try this again. Let's delete this one now.
OK, so now our program is still OK, no yelling at us. This is
fine and this is fine and if I run it, even though it's not in
here, it's not in here because of inheritance like we just went
over. It's right here and we'll get it. But what happens we
don't want.
We don't want that.
We don't want this to be able to get access in two different
spots, right?
Through inheritance like, we want that to be abstracted. We
don't want you because I can come here and say, OK, well,
what? Why can't I just do this? You know, get connection string.
You know, get con.
Equals, you know? And then I could say, you know get
connection string.
So really I'm repeating myself 1/2 and three times here but.
I'm inheriting it, so that's fine and I'll and I'll. But I
don't wanna be able to access this class now because this
First off is sensitive information. You don't wanna get
that information to begin with from anywhere other than the
derived classes. And here you're literally be able to see it.
So what do we do? We do abstraction, alright?
So we can put in the abstract keyword here.
It'll be fine here. It'll be fine. Here. Here, now. Soaring
an error.
I cannot create an instance of the abstract type or interface
get connection string.
But what the heck is going on?
Basically I am hiding this class from being able to be accessed
OK. If I delete this and I try again get connectionstring it'll
generate because it's a class, right? But if I'm trying to
renew it up, you'll start yelling at me equals new.
Get connection string and there it is. It's not you at me and I
came in. I won't be able to.
Do this either because it'll yell at me here.
Right here. It's yelling at me still.
So.
That's how abstraction works. It's your you're abstracting
your data from being able to be viewed. I could. It still works
here. If I run this program, it will just make sure no wires
here. Yep, there it is.
I know I changed that earlier, OK.
Uh, if I run this program?
Right there gets the connection string, gets the connection
string. Ran totally fine.
I'm still getting this, I just can't access it on the main file
now, which is good. That's abstraction. That's what you
want. You want it to be able to do that. It hides it for you.
That's.
The easiest way I can explain abstraction right there. It's a
mix of a base class, but it's also a mix of interface because.
If I was to add in another property here, it would want it
or another method it would want me to inherit those properties
and methods directly into these classes. They would have to
contain them.
And so basically, unless you're gonna use everything,
abstractions probably not the best idea.
But it's a good idea if you want. If you're gonna be using
your code in multiple places, code that you need to be
abstracted to be secured and you know that you don't want to be
in manipulated on the main file.
Right.
Let's move on to polymorphism. This one is a cool one right
here that you guys will be cool. Be psyched about this one
hopefully. Hopefully nobody sleeping on me.
All right, polymorphism.
So let's go back to our PowerPoint slide here.
Work yourself in a core. Yep, Yep, polymorphism. Here we go.
Alright. Literally means many or multiple forms. The third pillar
of OOP.
The process of being able to return different logic from a
single method based on a particular situation.
So basically, if I have a method that says, hey, you're gonna
send this message out, but then something happens and I'm
already planned for that, something I could say, well, if
this is if this happens, you get override and you could write
something totally different without even having to change
anything at all. It's pretty neat.
This is achieved with the use of keywords virtual and override.
The virtual keyword goes on the calling method and override goes
on the method to be changed. Polymorphism is not to be
confused with method overloading, which I'm gonna
talk about a little bit very quickly.
Right after this.
Not as common as inheritance or encapsulation, but it's
extremely powerful.
Methods are overridden and the runtime compiler and not the
static compiler. So basically you have two compilers. Your
static compiler is the one that runs all your code, and that's
the one that usually yell at you when you have errors in your
code. So.
That's your static compiler. When you run into those problems
and I'm sure somebody here has run into it as well. When you're
starting to program and let's say you're doing a web page and
you go to Web page and I know your website crashes, but it was
running totally fine 2 seconds ago. That's your runtime
compiler, your runtime compiler saying, whoa, hold on, I don't
have that information that you set out was going to have when I
got to this point, I don't know what to do so I'm breaking.
That's your runtime compiler, OK.
So this is what is overwritten. The runtime compiler says Ohh
you wanted to do something else with that code no problem. I got
you. I'm gonna do it for you.
Alright, polymorphism. So let's go ahead and create a new
animal.
For he was animals. Again, I love my animals.
I do.
Polly animal.
OK.
This is just for purpose sakes.
So polynomial.
And we're gonna go ahead and make a public void.
And where do animal sound alright? Simple. All animals
make sounds pretty much so why not?
And we're just going to say, make an animal sound.
All right.
We'll stuff.
To make a few more, a few more animals here, because I love my
animals, let's make a.
Let's make a pig.
OK.
Same idea with a. Just take this case. We're gonna pretty much
use the same thing over and over and over again here.
So we'll do pig, we will do dog.
Yeah.
And one more, we'll do lion, cause why not something totally
different.
All right, so now let's implement all these classes
here. So we have polynomial is now Polly Animal. OK, we'll do
pig.
Pig, pig. What else did we make? We made a dog, dog, new dog. And
we'll do a lion, lion, new lion. OK.
We'll stuff. Why is this yelling at me?
Dog is a type which is not valid and again ohh OK there it goes.
I guess I just have to read it.
OK.
So.
Here we created our classes right?
Alright.
Well, let's go ahead and see what each animal sound is.
Right. So we're gonna say console dot writeline.
And we're going to do.
Actually, let's go do this right here. We're going to do Poly
animal sound dot animal sound.
That's one lowercase P here.
Animal sound.
Alright.
Pig, not animal sound, animal sound.
Dogged out animal sound animal sound.
And lianda animal sound animal sound alright?
I did forget to mention that we also have to inherit again.
Or inheriting that polynomial class, which is fine.
That is fine. So we're going to inherit that right there. We're
good. Let's run this, see what happens.
Make an animal sound all these, say, make an animal sound as
expected. Here. Right? Makes sense.
Let's see what Poly uh polymorphism does for us so.
Let's go ahead, and we're gonna do this. Let's change this
animal sound. So we're gonna write this. The virtual keyword
that we talked about in that slideshow.
And over here, we're gonna say.
Said of this, we're going to say the pig goes oink.
I don't know.
He goes a link right.
And we're gonna use that override method. I mean the
override keyword we're used before.
And explain this a little bit more in a second.
Override. We're gonna say what the dog is actually gonna do.
A dog goes woof.
And we're gonna say with the lion actually does.
Lion roars. I don't know.
And again override.
What is that?
OK.
So now I changed it. These three spots I just gave the override
keyword and I said what the dog and the pig and the line
actually do. I didn't even touch this at all.
Let's run it.
Animal makes a sound. Pig goes oink, dog goes woof. Line rows.
What just happened?
I said to the compiler, to my program I said, hey, Polly
animal, get me my animal sound. No problem. I can do that comes
in here. It says OK you're gonna make an animal sound virtual. It
keeps us in the back of its mind that says virtual. OK now I know
when I'm getting animal sound with a class that's inheriting
Poly animal I'm going to override whatever is on the
other end because it should have an override keyword.
So when I came over here and said pig, get me my animal
sound. It came over here and said, Yep, there's my override
keyword animal sound that's inheriting from Poly animal. Oh,
it's something totally different. But I'm OK with that
because you told me that was gonna happen. You told me that
it wasn't going to be make animal sound. You told me that
it was going to be the pig goes oink.
Same thing here. Same thing here and that's why you get a
different result here.
Even though we'd even change any of this code we just added in
the override keyword and we threw in whatever it said.
That's polymorphism. Now a lot of people get this mixed up with
method overloading which we are going to talk about right now.
So we're going to start with constructors.
OK.
So here are some constructors we're gonna do the constructors
first in a class because I told you that I was going to tell you
a little bit about that.
So let is let us make a new class and we are gonna call this
one greeting message.
Alright, reading message here.
Perfect.
And we are going to give this.
A property and it's gonna be a string.
And this is going to be a message right. Now, here's the
thing. We'll constructors. If you make a constructor. If
you're making a class, every single class that you ever
create in your programs automatically come with a
constructor built in. The compiler will make one for you
if you don't initialize one yourself. So if I left this
blank and I ran this program, it would be no different from
leaving a blank than it would be if I made a constructor and left
it like this.
Nothing would be different. It's the same exact thing because.
The compiler makes one for you when runtime starts.
If you don't already have one specified.
So here we're going to do.
Message is equal to.
Hello world right?
Now, what if you wanted to pass something into this class and
you wanted to set the message to something else? What if you
wanted some sort of message in here, right? So let's say you're
going to expect the user to pass in. You're gonna expect
something you pass in here like a message, right. So you say,
OK, well, they're gonna pass in their name.
So you're expecting a string name totally fine, and now the
message instead of saying Hello World will say.
Where you string interpolation again.
Hello and we're going to give it the name that was passed in, OK.
I'll see what happens here. Let's close all these guys out.
Keep our program kind of narrow down a bit.
Alright, so let's make us our constructor here. Let me just
put another break spot here. Oops.
And do that.
OK, so let's make us our greeting message greeting
message, OK.
Breeding dot message.
Actually, let me do console airline that probably help,
right?
Reading dot message.
So now.
I'm not giving it any parameters here, I'm just saying greeting
message, no parameters. So when this runs it'll come here and
I'll say Yep, this is what I'm getting. That's what this will
be.
However, if I say you know what, what if I want them to have the
option to get a name?
Greeting message. I'll just do greeting one right. Actually,
I'll do greeting with string.
As new greeting message and instead now I've just nothing.
I'm gonna give it a parameter of Jordan because that's my name.
Why not?
And greet and where the consulate line.
Reading string dot message.
So now when this comes here.
Will come here and I'll say, OK, you gave me something, so I
don't need this one because I know this is the one I want now.
Because you gave me a string.
And I'm going to say, OK, messages now, I'm gonna say
Hello, Jordan instead of hello World. Let's run it and see what
happens.
There it is. Hello world. Hello, Jordan.
Because I changed what was given to it and you can keep doing
this all the way down. I mean, you could, you could go
constructor. Let's pass in a string name and age, right?
And we're going to do, you know, now the message is gonna say
string interpolation again hello.
Uh. Name.
Hello name.
You are.
Age.
Years old, right?
And we'll do one more over here.
Greeting message string name and age and we'll do string last
name.
Right.
And where you send the message now 2.
Hello.
Name.
You are.
Age years old.
Hello Jordan. Last name.
OK.
So now let's go back to program. We're going to use all those
that we just give it gave it. Sorry.
Greeting message.
Creating one. Alright, so we're gonna give it a name. So we're
gonna say Jordan.
And this one, we're gonna give it the age. I just turned 27.
Today is actually my birthday. So we're gonna do that.
And we're gonna say greeting or console rate line. This could be
greeting one dot message.
And then we're going to do the same exact thing.
Here I'll just copy that in.
Pace it again, and we're gonna say.
And he said to my last name.
Change that to greeting two greeting 2.
OK, so now we should get 1234 different messages. Let's run
it.
Yep, hello world. Hello, Jordan. Hello, Jordan. Are 27 years old.
Hello. Jordan Mendes. You are 27 years old. Done.
That is constructor overloading.
Right there, you keep the same exact name and you're passing in
a new parameter for each time you need to overload it. Now you
can pass in parameters here. However, you cannot like. I
can't say OK well, I'm getting a name in this one, but I don't
need a name here, but I only need a string so I'm not. I
can't say like. OK, well, I'm going to give it a string of, I
don't know job position or something because will yell at
me. It'll say you already have a defined parameter constructor
with the same parameter types.
Of string which is name. It doesn't care what this is. This
is just a name of whatever you're giving. It doesn't care.
It cares that you're giving it a string and you give it a string
up here and it won't let you do that.
That's what it's meant. That's what it's telling me for right
here.
All right.
Same idea here methods. This is the last part of it.
So hopefully you guys are.
Still with me on this one? Alright, so.
Last but not least, we're going to create one more class, our
last class, and we're going to name this one book.
What we just did, we could do again with methods. OK, so we'll
sign a book. Some properties. What is a book? Have a book. Has
a string title, right?
String title.
It has a N of pages.
Right, it has a string and it has an author.
And then it has a.
String of genre, right?
OK.
So now.
We're going to create some methods public void add book.
Alright, because either way, no matter what we're doing here,
we're gonna add in a book. Well, if we're gonna add in a book.
Right at very minimum. If you're gonna add a book into your
collection, let's say you're adding to a library on some
database here, you're gonna add in a book each time. All right?
You at least need the title, you can't add in a book of No title.
That doesn't make any sense, right? So let's start off with
making a title.
OK. Or we can't use that word. We could use the lowercase T
here because it will yell at me because this is an uppercase T
and it will conflict the two.
So we're going to say title is equal to the title that we get
passed in, all right.
Umm, we're gonna go ahead and get these out of the way. So
public void add book.
String.
Title.
And number pages.
OK.
And we're going to say the title is equal to the title.
All right. Because we're getting that. And we're also say the
pages are equal to number of pages.
Alright.
But keep doing this all the way down here so I can literally
keep copying this and notice how the method has the same exact
name, same exact access modifier, same return type, same
name. Everything is exactly the same on it. The only difference
is that the parameters were passing in. This is method
overloading and as you can see you could kind of get an idea of
how this will be similar and get confusing with polymorphism
because we're getting a different result from the. We're
getting a different result from the.
From the method each time, but this is not method overloading.
I mean this is not polymorphism. This is method overloading.
Because you're overloading the parameter with different types
of parameters. Here you're overloading the method with
different types of parameters. Excuse me, I can't talk right
now. I've had any coffee this whole time.
Their name and finally genre is equal to type of genre. Alright,
so here we go. Let's make us some books, right?
So here we're gonna first initiate the class of book book,
book sequel, new Book. All right. And then book dot.
Uh add book, right? Because we're using that method. Now
let's highlight this for a second.
See, it says right here string title. So it's expecting at
minimum of title, but then there's three other overloads,
right?
Three other overloads, and this is common with a lot of classes
you'll see are a lot of methods you'll see in C or in Visual
Studio or whatever, whatever stack you're using C you'll see
it if you highlight this, it will drop this little tile down.
It'll say OK, you're getting a return type of void. The class
name is book, the method name you're using is add book. It's
expecting a string that's going to be called the title, and then
you have three other overloads, meaning that the three different
versions of add book method.
Alright.
So let's do for a title Harry Potter and the Chamber.
Of secrets.
That's why not.
Console write line some string interpolation all right.
And and.
We're going to go ahead and do.
We're going to go ahead and get that book out of.
That classroom just made. This is a add book.
With only.
The title.
Let's give it a new line, new line.
And we're gonna say the title.
Is going to be book dot title, right? We're gonna pass it all
the parameters. I wanna show you how these are null when you
these are all null when you first make.
This class because we haven't assigned it to anything yet.
Right. Because we're still we have, we are only accepting in
the title right here. So all these other ones are gonna be
empty or no, they're gonna either be 0 or they're gonna be
null because the default or an integer is 0.
So Janro is going to be book dot genre.
And we're just to give it some spaces at the end here, OK.
Let's run this.
Here it is.
This is add book with only the title. The title is Harry Potter
and Chamber of Secrets. Pages are zero because we didn't give
it anything. Author and genre both blank but we didn't give it
anything. All right, so let's just copy this and make it
easier on us.
Umm, we're gonna do console right line and we're going to do
new line.
Again.
You buck. But we're gonna say with the title.
And page number.
This time we're going to pass on the page number and so here.
We're going to do.
Where do this right here? So here's where passing in the
title on the Add book.
And we're going to give it the page number.
Which that's to the true page number there, by the way.
That's right, the line. OK, so now we have this book with title
and page number, title, pages, author and genre blinks. We
didn't give it that where before pages were zero because we
didn't give it before. Now we have it 341.
All right.
There's going to do this for the other two. Get it out of the
way.
OK, Chamber of Secrets 341 author is JK Rowling.
OK.
And then.
Lastly.
JK Rowling.
And we're going to give it the genre of fantasy.
Alright, now if we run this.
There it is. Alright, so we have our first book, just the title.
No pages don't offer no genre. Second book. We gave it both the
title and the page number.
We have the title, we have the pages, no author, no genre. I
didn't change where it said with only the title page. I'm right
and changed that part, but basically we passed in the three
Harry Potter, the title we passed on the page. It's passing
the author and the last one we passed in everything.
And every single time it gave us back only what we passed in and
only what was stored in.
This is good to use.
When you have basically a.
This is good to use when you have a.
Something that could be added to a database that doesn't need to
have all the information saved to it right off the bat. So
example a book all you need is a title. Fine. OK you can just
take the title in if you have the page numbers, that's a plus,
but you don't need the page numbers if you didn't want it.
So.
That is my whole entire presentation on OOP, some method
overloading and encapsulation, abstraction, polymorphism,
method overloading and creating the empty constructors within a
class. So hopefully I didn't bore anybody lose anybody.
But yeah, I mean that's it.
Thank you, Jordan. That was very interesting. I remembered a lot
of things that I forgot.
So thanks, that was awesome. I I do like the the way you teach.
No worries.
I try, I try to make it so that way I cause originally this was
supposed to be just a slide show here and and I said, you know
what? What's what purpose is gonna be.
If I could actually just show it.
Yeah.
So that's why I decided to do that.
And happy birthday.
Thank you.
Happy birthday, Jordan. That was awesome.
And and if you don't, you don't know me well enough to know that
Thank you. Thank.
Happy.
I actually hate code more than anything on the planet. I don't
understand it, but actually, after all the years I've been in
school, I understood that presentation more than any other
class I've had. So good job.
Thank you. Thank you.
Really good job.
I I I faked faked my way through the classes. Don't tell anybody
Jordan.
I was.
It's like but good job.
Jordan, this is doctor Chicone. Great job. Great job.
Thank you.
So does anybody have any questions? I know that was a
pretty long presentation. I was trying to really hurry it up
and.
Get close to that 45 minute time break there. But I wanted to
make sure that I was pretty pretty in depth with a lot of
stuff I was going over as much as I could be in that timeframe.
No questions from anyone.
All right. Well, once again, thank you so much, Jordan, that
that was really great. And of course, anybody who didn't get
to see it or wants to watch it again, it will be.
And obviously we recorded it so.
Great job again and happy birthday.
Thank you. Thank you.
Have a great night everyone.
Don't forget to clock out.
And you're done.
Don't use break.
Oh man, I didn't even clock in for that.
Oops.
Jordan, how are you gonna graduate with these hours that
Ohh well.
you don't have?
It's pretty sad what? I didn't clock it. I was like, yeah, this
is what it is because I know I'm already fine.
And I just wanted to say to that, Monica, in Tabitha are
doing presentations next week. They're 15 minutes, so there's a
slot open.
And yeah, there's a lot of free slots, though don't forget to
sign up.
The way you sign up for master class David, I'll actually show
you since I'm still screen sharing. Here you go. Here you
go to your files.
And then it should be in here somewhere master class weekly
meeting. Now, where is it? At here. Yeah, right here.
I think it's at the top because I just clicked on it, yeah.
Master class training sign up sheet click here.
And you can go ahead and Scroll down.
And you just go to today's date or whatever date so that to this
obviously today.
So you can sign up here for 1515, so another 15 minute or 30
minute here.
They usually it's supposed to be a 315 minute presentation, so
three separate people at 15-2 separate people at 30 a piece or
one at 45. So like today, I did the little over 45, but.
Umm but yeah, and just so you can have a 50 minute Q&A at
the end mainly.
No worries.
Alright, if no one else has any other questions, everyone have a
great night. I'm gonna stop the recording.
Alright, have a good night.