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

Download "Java для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры."

input logo icon
Video tags
|

Video tags

Инкапсуляция
джава
ява
сеттеры
геттеры
java для начинающих
Encapsulation (Programming Language Paradigm)
Programming Language (Software Genre)
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:02
about methods, we learned how to create,
00:00:05
how to return a value and how to
00:00:09
pass arguments to them, and in this lesson
00:00:11
we know about encapsulation, what it is
00:00:13
and why it is needed, we have a class of songs
00:00:17
from previous lessons and we have a class of
00:00:19
another cool object in which the
00:00:23
main method we create an object of the song class and
00:00:25
pass these values ​​to the fields and what’s
00:00:31
bad about this program
00:00:32
and what’s bad is what we pass, we access the
00:00:35
fields of this class through a dot, that is, we
00:00:38
directly access these fields
00:00:42
now I’ll try to demonstrate
00:00:44
the shortcomings of this approach, imagine
00:00:47
that you are programmers, you are writing a large
00:00:49
program that will be used by the
00:00:51
end user,
00:00:52
not a programmer, an ordinary person, and
00:00:55
imagine that this class, that is, this is
00:00:58
your program that you
00:01:00
wrote, and here the
00:01:04
end user accesses your created
00:01:07
class and uses it in some way So,
00:01:10
what is the disadvantage, what is the disadvantage of
00:01:13
directly accessing your fields, but the fact is
00:01:15
that all the same, these fields should be
00:01:20
hidden from the user because you are
00:01:23
carrying out some actions with them inside the
00:01:24
class and this data should be for
00:01:30
internal use, why because
00:01:33
that for example you may want to change
00:01:35
your name in a field because you
00:01:39
needed to
00:01:41
do it in the internal work of the class, but
00:01:45
at the same time your end user will
00:01:48
no longer be able to use this field
00:01:51
because if you change, for example here,
00:01:53
logically the class no longer fits
00:01:56
my name the name user is suitable for you, for example,
00:01:59
if you do this, then your user will
00:02:02
not be able to use this field,
00:02:07
another example, for example, your user is
00:02:11
not a very smart person and he wants to
00:02:14
set an empty name,
00:02:18
so for this class to work, you are asked to
00:02:21
you need a non-empty name and you
00:02:23
naturally need some positive is also
00:02:25
not empty positive is not empty
00:02:27
numeric value for age your
00:02:30
user sets empty exactly example
00:02:33
empty name and sets negative
00:02:36
age to straight minus five years if you
00:02:39
run this program let's
00:02:41
run here we will output red. speak
00:02:47
if we allow this that that everything will
00:02:52
work that is, there is no name there is a
00:02:56
negative age but the program
00:02:58
works and it works again and the warmth
00:03:00
and reason that the user can
00:03:02
directly access the fields of the class
00:03:05
what would we do if he accessed not
00:03:09
directly but through methods in these methods we
00:03:12
could place a check that is,
00:03:14
before we assign a value to these fields
00:03:18
we in these methods methods
00:03:21
check and either positive years
00:03:23
values ​​if we are talking about age or
00:03:25
not empty years and value if we are talking
00:03:27
about about the name and these are the methods in which
00:03:30
we check that these methods serve as
00:03:36
such a layer between your fields and
00:03:40
between end users, these methods
00:03:42
are called guitar setters and now we
00:03:45
will create them
00:03:46
in general c3 guitars this is a standard
00:03:51
agreement and they are used in any
00:03:54
type of this
00:03:56
application this is a public interface in my opinion in
00:03:59
general, in simple words then five
00:04:02
is the interface through which the
00:04:04
user gets access to
00:04:05
the functionality of the program and the user does not
00:04:09
need to know how everything works inside
00:04:11
the user, you should only give
00:04:13
some kind of interface through which he can
00:04:16
get the necessary functionality and the
00:04:19
user should not touch the
00:04:20
internal structure of the program the
00:04:22
name for this is we we don’t give the user
00:04:26
access to the variables themselves, the fields of the
00:04:28
class modem access only to the public
00:04:31
method, so let’s make these fields
00:04:34
break through rule this
00:04:39
keyword which means that this field is
00:04:42
accessible and visible only within this
00:04:46
class and you see that as soon as we
00:04:48
made the
00:04:51
name variable they rule,
00:04:54
since it has already ceased to be available in
00:04:57
other classes, that is, if you put a
00:05:00
keyword about it in front of your field
00:05:02
in the class, then this field is now
00:05:05
available only within this class,
00:05:08
in particular within the class of persons
00:05:11
within this class, and
00:05:12
you see we can use
00:05:14
change and use this change,
00:05:16
but in other classes we cannot do this;
00:05:19
if we hover, we will see
00:05:21
the error name has provide access in asks,
00:05:26
that is, to configure it and we
00:05:28
cannot use it in these we also make the
00:05:31
right about it and which provide and you will see
00:05:36
that now we cannot use and
00:05:37
bake so now the user of course
00:05:40
cannot get direct access to
00:05:41
the fields so we can erase this how
00:05:47
now the user will
00:05:49
access these fields how will he
00:05:51
assign them how will he receive the
00:05:53
value he will receive the value
00:05:56
through a sieve and leggings for this, let's
00:06:01
first make a garden arbiter for the name
00:06:05
and then make it for age for this
00:06:08
we write public white hearty parameters
00:06:17
we write string name string let it be
00:06:23
lake and here we equate our
00:06:29
field to this value that came
00:06:32
in our time parameters equals username
00:06:41
now based on us can
00:06:45
assign a
00:06:46
name using this method by passing a
00:06:50
string to the parameters and in this method we
00:06:57
assign this field a string
00:07:00
passed passed their parameter and
00:07:03
pay attention to the fact that our method is
00:07:05
white because it does not return anything
00:07:07
only assigns but another get method
00:07:11
we will have with a return type of
00:07:15
string because it will
00:07:17
return a string
00:07:19
public string drinks name with name empty
00:07:23
parameters
00:07:27
when calling this method we will have a
00:07:30
string returned
00:07:31
which is a field in this class
00:07:35
let's do the same methods for the field
00:07:39
and public would set ych
00:07:45
here in the parameters we now have no
00:07:48
string but int int user speech here also
00:07:55
needs to be done so user speech and in the
00:08:01
method we have ych equals user speech
00:08:08
again howls here int and method public
00:08:14
int int and because we will return
00:08:18
an integer with a numeric value
00:08:21
public and get rich [ __ ]
00:08:28
we have four methods in each of them
00:08:30
means
00:08:32
in each and here is a pair of
00:08:35
methods a pair of methods intended for
00:08:38
this field and a pair of methods
00:08:40
intended for 2 fields now in
00:08:42
another class
00:08:44
we can access these fields through
00:08:48
these methods and let's try again.
00:08:58
set name some name
00:09:03
ps one one .
00:09:07
set h any number and ps one
00:09:13
that speak we will return call a method
00:09:17
that will greet us three times
00:09:19
and give out the age and
00:09:22
you will see that we first managed to get a name
00:09:27
and we got
00:09:31
the age set using these methods
00:09:34
we can also return name and age
00:09:38
using their corresponding
00:09:39
tagged methods one .
00:09:43
get rich and let's write here that
00:09:47
we will display the first ones on the screen and write
00:09:49
that
00:09:53
we will display the value in my method
00:10:01
so and so
00:10:09
and here we do the same thing, let
00:10:23
's run
00:10:28
on with the help of Hitlers those
00:10:31
variables that we assigned with
00:10:33
the help of sidors with the help of guitars we they
00:10:35
were brought out in another class, what is the advantage of
00:10:40
this approach, but the fact is that now we
00:10:43
can, for example,
00:10:44
inside the class, we can change the name of dreams for
00:10:48
him, for example, to whatever I want, to I
00:10:50
don’t know, login, for example, any name,
00:10:56
and here users will no longer notice
00:10:58
this because inside of this class in the
00:11:00
methods we will simply change the internal
00:11:04
logic of the internal logic of our class and
00:11:06
you see that nothing has changed for the user,
00:11:09
he accesses this
00:11:12
internal variable using the same
00:11:14
class, but the internal variable can
00:11:17
change in any way if we run something like this and
00:11:20
so we change the login inside
00:11:26
class one more variable and lower it and
00:11:32
you will see that nothing has changed besides
00:11:38
this, we can in these methods in satires
00:11:40
we can check the correctness of
00:11:44
the water, that is, for example, our
00:11:49
user cannot have an empty name
00:11:50
because the person must have a non-
00:11:52
empty name for this, we check
00:11:55
the username here
00:11:56
let's return it back to them there are already
00:11:58
aunts on them more logically name is we also do
00:12:04
n’t know and here we will check if it is not
00:12:12
empty or the user has provided us with a
00:12:14
name at the input for this we will call the
00:12:18
is empty method which is available with
00:12:21
string and we will return this method
00:12:23
true if our line is empty I
00:12:28
returns falls if the line is not empty
00:12:32
therefore if user is empty we print the
00:12:35
error you entered an empty name body
00:12:40
my name is els otherwise els
00:12:47
we assign the user username so here we have a
00:12:53
fuser name is empty so here we write
00:13:00
and now our user
00:13:04
will not be able to set an empty name because in the
00:13:07
center we encapsulate the necessary logic
00:13:12
that has checked that will check the
00:13:14
correctness of the water and let's
00:13:18
do the same for set it if you zerohedge that
00:13:24
is, the age that was submitted is
00:13:25
greater than zero, strictly no longer possible, then
00:13:30
we assign not let's do if
00:13:33
less than zero then we display an error then we display an
00:13:38
error we write south
00:13:45
incorrect so age must be
00:13:48
age must be positive els
00:13:54
assign age if we
00:13:58
run it now nothing will change let's
00:14:01
stop calling this speak and
00:14:05
call it like this they see name and
00:14:09
+ online everything is acceptable nothing
00:14:18
the same name has not changed, the same age,
00:14:21
but if we now try to assign an
00:14:28
empty name and run it, then first of all
00:14:34
our program will give an error and you
00:14:41
see what it means here that the
00:14:43
name variable is not I did not assign
00:14:47
the value that was supplied,
00:14:49
we will do the same thing with age, if we set an
00:14:51
empty age, or rather empty and
00:14:53
negative, then our program will display a
00:15:02
message that the age must be
00:15:04
positive on this main day
00:15:07
of surrender
00:15:08
once again, you must
00:15:10
limit your fields as much as possible from other classes,
00:15:13
that is, you must do so that, if
00:15:15
possible, your fields were visible
00:15:18
only within one class of the class in
00:15:21
which these fields are
00:15:24
declared and you must access these fields
00:15:27
through a
00:15:28
setter
00:15:29
and through getters

Description:

МОЙ НОВЫЙ КУРС: https://www.youtube.com/watch?v=rRe1vT0SDD8 ПРАКТИКА НА JAVA: https://java-marathon.tilda.ws/ Реклама и сотрудничество: [email protected]

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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры." 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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры." 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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры." 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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры." 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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры."?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 для начинающих. Урок 18: Инкапсуляция. Сеттеры и геттеры."?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.