Hello again, everyone.
So today we're going to talk about generic types, so now when we think of software development, one
of the purposes is to create components that we can use over and over again.
So, in other words, will aim to develop a structure that we design today and it's flexible enough
to provide us with our future needs as well.
So that's why we talk about generics, because generics are structures that allow us to work in different
types, not just one time.
All right.
So we can say that it supports flexible future proof, whatever you want to say.
That's the way I see it anyway.
All right.
So why don't I show you what I mean with an example?
So I'll just write a simple function that returns a number.
And this function takes a number as a parameter.
And now define a variable using this function and define a number.
I print this value on a console, run the program.
And as you can see, the value we give, so look here, we've specified the dysfunction will take a
number of value.
Of course, I get an error if I write a string value.
Right.
And likewise, if I want to print a console string value, it needs to define a second function.
So that means I also need to define the second function.
So this function also takes string value and the return type is string again.
So, again, I'll define a variable that uses this function.
And then I'll print the console.
So, in fact, we don't see any problems here.
Well, mainly because there aren't any problems.
However, as I mentioned in the beginning, the aim is not to repeat the same thing.
We want to be able to use the structure over and over again.
So now I'll show you by writing a third function.
So now if you're typing the function and name will define the type this way, then again, that type
of value to get and we'll define the type of value to return.
So now look at our use of tea here, it comes entirely from the word type, you know, its first letter.
Now, we can also use values like A, B and C if we want to.
But sure enough, see how this gives us a way in.
Now, as above, I want to print a number value to the console first, and I'm sending a number of value
to the last function.
So now let's send the string value to a third function and print console.
Look at that, don't get years because we've not specified here which type we're going to work with,
we said here that we will get a type with a letter T, but we didn't specify this type.
So when I want to use two different types here, I can just use the same function.
That's what using generic types are all about.
Now, before finishing our lesson here, I do want to show you the generic structure and classes.
I'll just write class and write name.
Then I write the generic type that we use just before.
So in this class, if I want, I can define a variable and use that, or we can make a function definition
and we can continue using it here.
And we create an object from this class, so here I specify that I will use no as a variable.
And when I call this function now, it says I need to send a number of value.
We stated here that there will be a No.
Now, if we use a string here, yeah, it'll give an error.
Because it's expecting and wanting and was going to ask us for string value.
So you see how the logic is the same, but instead of using a definite type, we use the generic and
then we can use different types that we want to for the same class.
So what this does is prevents us from just doing different classes that are going to be doing the same
thing each time.
Who wants redundancy?
So, sure enough, my friends, we have come to the end of this lesson, we've got rid of some repetitive
tasks thanks to the use of the generic right.
So take care of yourself until our next lesson.
I'll see you then.
Bye for now.