Hello and welcome to the Golang programming language course in this session.
We want to talk about interface concept.
In their faces and go blank.
Go language interfaces are different from other languages in gold language, the interface is a custom
type that is used to specify a set of one or more message signatures.
Interface is abstract, so you are not allowed to create an instance of the interface, but you're allowed
to create a variable of an interfaces type and display, but it can be a sign with a concrete time value
that has the metals being their face requires or in other laws.
Dana Face is a collection of missiles, as well as cost them time.
How to create an interface to create an interface using either face keyboard, followed by clearly braces
containing a list of method names along with any parameters or returned values.
The missiles are expected to have.
Now you can see the scene techs.
Declare an interface, time and missiles does not have a body and in their faces act as a blueprint
for method since they must be implemented before being used.
Type that satisfies and interface is said to implement it.
How to implement interfaces.
In the gold language, it is necessary to implement all the methods, the clearing, the interface for
implementing an interface, the gold language interfaces are implemented implicitly and it does not
contain any specific keyboard to implement an interface just like other languages.
Let's go to this school program to illustrate how to implement an interface.
First, go to Explorer and create a project folder like in interfaces and create a file name Lee.
So let's go hack each main and function function.
First, create an interface named rectangle and has two methods for triangulate rectangle three Trinitarian
area.
Tie.
Rectangular.
Interface
and create two methods.
Preemie to return tide is low 64 and area uterine tide is again below sixty four, set a common for
these NFA for export
rectangular interface.
In order to be able to use the methods of an interface, we need to implement them to implement the
methods of interface.
We need to create a struct now creating an abstract.
Times
change.
Q Let's say the name for this is right.
That's right.
This is wrong.
It has two fields length and type of fields to load 64.
And the other is weeds.
Typekit is in the game.
Loads 64.
Sit the comment for export, distract,
calculate, distract.
OK, now implementing methods of reigniting your interface via the striked receiver.
First, implement pre-internet or farm city receiver.
C Calculate
free meter
and return time flow.
64 and dismantled reader
C dot widths plus C dot links.
And told her medication to
set a common for dismantled three metre missile and second in demand early on, this would
find three Silver Sea calculate and area that will reach inside to load 64 and set of body for this
method later.
See, don't this multiplication see the legs set the common for peace central
area?
OK, now go to main function for accessing elements of the rectangle interface.
Go to the main function.
First, create an interface value that from the H9, get and then initialize it by calculate struct
that are rectangular.
Define and variable from a rectangle in the first and in the next line, the initial lines are by the
calculator strikes are equals, calculate for the example, 20 and 10
now invoke rectangle interface, metals and display, then go to the next line.
If P
three metre or rectangle color are dots printer, go to the next line.
If P area of rectangle column, ask dot area, reformat the code, save the project and execute the
program first.
Go to Project Folder, see the interface and run the project by the Kremlin to run.
Name the group.
Now you can see the output in this case.
First, create an interface has two methods four.
Calculate a rectangle, perimeter and area.
In order for us to be able to use them, we have to implement them, so we create a strong name, calculate
and implement two rectangle interface methods and assign them to instruct.
Now define variable from rectangle interface and initialize.
It will calculate the strike and coding tooling interface methods and see the result.
Assigning an instance of calculate strike to a variable of rectangle interface, time works because
calculator strike implements both perimeter and area method of the calculate.
The time is not changed during this assignment.
Instead, it is enough to check that the type assigned does implement perimeter and area method in order
not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.