background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы."

input logo icon
Video tags
|

Video tags

курсы java
программирование на java
обучение
программирование java
классы
изучение java
программирование
java для начинающих
java для чайников
android
языки программирования
обучение java
java
интерфейсы java
язык программирования java
jdk
java с нуля
boostbrain
онлайн
основы программирования
абстрактные классы
уроки программирования
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:01
Hello friends, today we continue
00:00:04
to delve into the topic of
00:00:06
object-oriented
00:00:07
programming and consider such
00:00:11
concepts as interfaces and abstract
00:00:13
classes in this place. For those who have not watched
00:00:18
previous videos dedicated to the class
00:00:21
method of classes and
00:00:22
object-oriented
00:00:23
programming, I
00:00:24
advise you to review these videos,
00:00:28
and for those who have not yet I
00:00:31
haven’t subscribed to the channel, I advise you to subscribe
00:00:33
because not a single large complex topic
00:00:36
can be discussed in one video
00:00:38
and will inevitably be broken down into
00:00:41
some sequence. Well,
00:00:45
now let’s move on to the topic, let’s start with abstract
00:00:47
classes since they are more similar to
00:00:50
the classes that we are already accustomed to
00:00:52
using abstract class this is a class
00:00:57
from which you cannot create an instance, you
00:00:59
simply cannot write
00:01:02
new the name of an abstract class, the only
00:01:07
way to use an abstract class
00:01:08
is to create a descendant class,
00:01:11
well, it would seem, why such complexity,
00:01:14
why create some abstract
00:01:17
classes if you can create just the most
00:01:19
ordinary class,
00:01:21
but abstract classes are used
00:01:24
when related classes 1 part of
00:01:27
the methods are the same and others differ;
00:01:30
those methods that coincide
00:01:33
can be implemented in the base abstract
00:01:35
class and those that differ can be
00:01:37
implemented in descendant classes. The most
00:01:41
common example is, for example,
00:01:45
figures, that is, a figure in itself is an
00:01:49
abstract entity, but a circle or
00:01:52
square is quite concrete Essentially,
00:01:56
well, for example, if we
00:01:59
want to calculate the area of ​​a figure, then the
00:02:02
area of ​​the figure for a square and for a
00:02:04
circle will be calculated by different
00:02:07
formulas,
00:02:08
but on the other hand, if it is assumed
00:02:12
that this figure should be drawn
00:02:14
on the screen, then for example, the color of the figure
00:02:18
can be implemented by the same
00:02:22
function and using the same method, and then the
00:02:26
method for obtaining the color of a figure can be
00:02:29
transferred to the base abstract class and the
00:02:31
method for calculating the area can be transferred to the
00:02:37
descendant class. Abstract classes can
00:02:42
contain abstract methods.
00:02:44
These are methods for which there is only
00:02:47
a definition but no content, that is, there is
00:02:50
nothing in curly brackets.
00:02:52
This is a way to force yourself or other programmers to implement
00:02:56
these methods in descendant classes.
00:02:59
If you
00:03:01
work in a team, this is necessary so
00:03:05
that somewhere in some methods that
00:03:10
work not with concrete classes but with
00:03:13
abstract ones, you can
00:03:15
assume that such methods
00:03:17
will definitely exist, for example for the same
00:03:21
figure, you can write an
00:03:23
abstract class that will contain an
00:03:26
abstract function to get the area and
00:03:29
thereby force everyone who will
00:03:32
inherit from this class
00:03:35
to implement this function; this method
00:03:38
will be different for all types of
00:03:40
figures; consider the interface and the interface and is
00:03:46
similar to abstract classes but is
00:03:49
defined by a keyword interface
00:03:51
instead of
00:03:52
abstract class, now let's look at their
00:03:57
difference and this question is almost always
00:04:01
asked in interviews: how does an interface differ
00:04:03
from abstract classes?
00:04:07
One of the main differences between an interface and an
00:04:09
abstract class is that in an
00:04:10
interface, methods are only defined, but there
00:04:13
can be no implementation at all;
00:04:16
no second main difference is
00:04:19
that when inheriting a parent
00:04:22
class there can be only one abstract
00:04:27
class, this is or usually but it can
00:04:28
only be one and there are as many parent interfaces
00:04:31
as you like, the
00:04:34
meaning of creating interfaces is to create a
00:04:37
hierarchy or a set of classes that are
00:04:39
united by a common meaning, that is, like
00:04:42
shapes and a
00:04:44
square and a rectangle and a circle is all
00:04:47
shapes and a set of methods with different
00:04:51
implementations, well, the example was already given above, that
00:04:56
is, for example, calculating the area or the
00:04:58
drawing method, and so on, but now let’s
00:05:03
move on to the practical part,
00:05:05
I’ll illustrate the examples already mentioned above,
00:05:10
when demonstrating the examples, we will go in a
00:05:13
different sequence, that is
00:05:16
first we will demonstrate interfaces and
00:05:19
then abstract classes, and in fact,
00:05:22
these rules must be followed almost
00:05:26
always because the abstract class is a
00:05:30
narrower entity and therefore we need to
00:05:37
start tying our hands and making an
00:05:41
abstract class only
00:05:42
if there is really a need for it, well, let
00:05:46
's start with interfaces, let’s assume
00:05:50
we have a vital need to make
00:05:54
some kind of method that will take a
00:05:56
list of shapes as input and print
00:06:01
some of their parameters in the console: the name of the
00:06:03
shape, the area, the color, and so on, what we
00:06:07
must do as
00:06:11
object-oriented programmers, we
00:06:14
must design this structure that
00:06:17
is called from top to bottom from the general to the
00:06:19
specific, respectively, that’s where we
00:06:23
start, we make an interface, we create an
00:06:30
interface, we call it sew, that is,
00:06:33
a figure, and here we begin to discuss
00:06:39
what methods, in principle, we will need
00:06:42
from a figure, well, for example, let this be a
00:06:46
method getting a name, a good method,
00:06:54
then let this there will be a meter for obtaining
00:06:58
an area
00:07:03
and let this be a method for obtaining color,
00:07:14
well, this is how we figured out approximately what it
00:07:17
should be and for now, without bothering,
00:07:21
we write a method,
00:07:33
let this method take as input a
00:07:36
list of figures in the list we went through in the
00:07:45
previous lesson, so
00:07:55
now we import using the for
00:08:04
loop
00:08:09
we output the data to the console,
00:08:14
each figure,
00:08:31
first we output the name like this
00:08:41
in the second line we output to the area
00:08:54
in the third line we output the color in
00:09:07
this way well, and this is
00:09:11
actually one of the miracles of
00:09:14
object-oriented
00:09:15
programming when we still don’t
00:09:18
know anything about any specific figures but already
00:09:21
We were able to write a
00:09:22
method that somehow operates with these shapes, here’s
00:09:26
what we
00:09:31
can do next, in order to
00:09:35
call this method we need to
00:09:36
somehow create a list, a list of
00:09:41
shapes, create it,
00:10:02
missed the words new, what’s next, how to
00:10:06
fill out this list if you write it
00:10:12
like this, if you try make an instance of the
00:10:23
shape interface, the compiler will tell us
00:10:27
that we can’t do this cannot be
00:10:29
instantly ted what to do next, we
00:10:35
need to define not abstract but
00:10:38
concrete shapes, for example, let’s create a
00:10:43
circle class and inherit this class from the
00:10:53
shape interface, here I’ll point out another difference, the fact is
00:10:59
that when we inherit from a
00:11:01
class, we write the word
00:11:03
extends which so and but and then some
00:11:08
class, and thereby we emphasize that we are
00:11:11
extending the base class,
00:11:14
if we inherit from an interface we
00:11:18
write implements, that is, it implements in
00:11:28
this way, now we see that food and
00:11:33
underlines in red underlines in
00:11:36
red for the reason that the
00:11:39
circle class, although it inherits from the
00:11:43
interface, does not implement any of
00:11:46
the methods that are defined in the interface,
00:11:50
we need to implement all these abstract
00:11:53
methods,
00:11:54
so before we give it some initial
00:11:58
content for them, let’s do this
00:12:06
name let returns everything
00:12:14
in order for us to have an area, we
00:12:17
must have a radius
00:12:24
[music]
00:12:33
so the radius must be filled somewhere, let it be
00:12:35
filled somewhere in the constructor
00:12:57
for now, what to do is just
00:13:05
fill in the radius and when calculating
00:13:12
the area we return it using the formula
00:13:17
314 1592
00:13:22
6 multiplied by radius once again multiplied by
00:13:28
radius wrote fro instead of retour and the
00:13:38
color color well, we also need to store the color somewhere so
00:13:53
we also need to pass the color in the
00:13:55
constructor so that we can
00:14:15
return the color,
00:14:22
well, there are
00:14:24
no errors, the class is defined,
00:14:27
we define the 2nd class, let it be there will be
00:14:33
a rectangle
00:14:41
like it also implements a figure with us,
00:14:53
let it return the name of the
00:14:59
corresponding rectangle y
00:15:01
now as for the area, in order to
00:15:05
know the area we need to know
00:15:08
the height and width of the rectangle, we set up
00:15:13
these two variables
00:15:28
and of course we should also have a color
00:15:43
so we have the area is calculated as the height
00:15:49
multiplied by the width, that is, the formula is
00:15:53
completely different than for a circle, and the
00:15:58
color is the color like a sphere,
00:16:07
now
00:16:10
these parameters also need to be determined in the
00:16:12
constructor,
00:16:23
we will have everything there, we will have
00:16:27
the width,
00:16:29
we will have the color, well, this
00:16:45
way now look here in this place
00:16:52
we can write
00:16:55
New York we define the radius and
00:17:02
some color is red for example as
00:17:07
you can see here polymorphisms
00:17:11
inheritance works in one person
00:17:13
since circle is a figure
00:17:16
since it inherited from the
00:17:18
shape interface it is also a figure and this is the
00:17:22
design perhaps we will add the newly
00:17:28
created figure to the list of figures,
00:17:35
but we can also use a slightly simpler figure,
00:17:39
ask the structure to be built like this, for example,
00:17:42
and define a rectangle with
00:17:54
sides 11 and let the color be blue.
00:18:02
Now if we call the method that
00:18:10
prints the figures with and pass it a list of
00:18:14
these figures, we will get the following
00:18:17
we collect and launch as you can see, we
00:18:25
saw a description in the console of the figures
00:18:33
that we entered,
00:18:39
well, this is how
00:18:40
designing from above is carried out
00:18:43
designing from above, it’s good because
00:18:46
we have defined the print ships method
00:18:51
which takes figures as input and
00:18:53
now this method will not change
00:18:56
depending on what kind of figure we will still
00:18:58
define, we can add another figure of a
00:19:01
triangle, oval, square, whatever we
00:19:06
want, but this will no longer change
00:19:09
and thus we got rid of
00:19:13
a lot of work, as if all this
00:19:16
changed depending on the number of
00:19:18
figures, but let’s move on, it’s already quite
00:19:23
obvious that besides what is different in
00:19:30
these classes, there is a part that is the
00:19:34
same for these classes, but if this
00:19:39
part were not there, then I would advise,
00:19:41
of course, to leave the shake interface and not
00:19:45
worry about it, but since this part is
00:19:48
the same for us, we end up with duplication
00:19:50
in the code,
00:19:51
then everything is better - so put this into some
00:19:55
common entity and this common entity
00:19:59
will be our shape, we remake the
00:20:03
spike interface into an abstract class like this,
00:20:11
then
00:20:15
if we have a function in an abstract class,
00:20:18
or rather a method in an abstract class is not
00:20:20
defined, then it should be marked
00:20:26
as abstract like this That’s how I
00:20:36
didn’t put the public keyword in the interface
00:20:38
because in the
00:20:40
default interface all methods are public,
00:20:46
just the interface doesn’t make any
00:20:48
sense without this,
00:20:52
so on and so forth, while we will have the get color method in
00:20:59
common and we define it, we
00:21:10
define it in the same way as and in the
00:21:14
classes of us in the classes of the heir, then
00:21:18
and in the same way we fill out this field in the
00:21:23
constructor
00:21:41
and the get color method will return
00:21:44
light. Now now this get color method
00:21:54
can be removed
00:22:03
from the heir classes and everything
00:22:08
connected with this color, respectively, and we can
00:22:14
correct the constructors from
00:22:23
everywhere by color
00:22:29
now it would seem like a penny
00:22:31
saving, but in reality when there are a
00:22:33
lot of class hierarchies, there is a lot of duplicate code,
00:22:37
then this leads to
00:22:39
significant savings and simplification, so
00:22:43
now since the shape has ceased to be
00:22:46
an interface, it has become an abstract class,
00:22:49
we need to replace
00:22:50
implement with extends
00:23:00
and here the most interesting thing happens,
00:23:05
here I defined the constructor for the
00:23:09
abstract class shape and here you can
00:23:13
ask me how I defined
00:23:15
the constructor if you cannot create
00:23:19
instances of this class, how
00:23:22
can this constructor be called and
00:23:24
this constructor can be called as follows
00:23:27
in the constructor of the inheritor class the
00:23:33
following super construction is written
00:23:36
and the color is passed to this super
00:23:42
in a super way, this is a
00:23:51
link to the methods of the base class, let
00:24:15
's define the same thing for the rectangle,
00:24:20
now we remove from the constructors those
00:24:22
parameters that have disappeared, collect
00:24:31
and run, well, the result is about the same,
00:24:36
only there is less code,
00:24:44
so we showed what
00:24:49
abstract classes are like them apply as
00:24:52
abstract classes how abstract
00:24:55
classes
00:24:56
differ from interfaces how you can
00:24:59
design from top to bottom and write
00:25:02
methods that take
00:25:05
abstract entities as input which may
00:25:09
not even be in the program yet which can
00:25:11
be defined later,
00:25:13
if you liked the lesson, like it,
00:25:17
if you didn’t like it, write comments and
00:25:20
ask questions for everyone bye bye
00:25:24
good luck

Description:

Программирование на Java для начинающих. Продолжение темы объектно-ориентированного программирования. Базовые сведения об интерфейсах и абстрактных классах. Пример использования, указание на различия.

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы." video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы." video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы." video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы." video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы."?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Программирование на Java с нуля #13. Интерфейсы, абстрактные классы."?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.