Students
Teachers & SchoolsStudents
Teachers & SchoolsIn this computer science problem, which of the following should be declared as private?
AP | AP Computer Science |
AP Computer Science | Classes and Objects |
Computer Science | AP Computer Science |
Language | English Language |
Standard Operations and Algorithms | Sorting |
Test Prep | AP Computer Science |
we're being asked which bits should be declared private Well
i don't want bring song name being that we're writing
an access or method called get song name specifically teo
get data from song name the string song name should
indeed be private things like this A private variable is
like your friends Your friend is overprotective of her kat
so she doesn't let anyone see it or pet it
However if you want your friend will bring the cat
out of the house and let you see it pet
It will bring the cat out whenever you ask her
to just his access Her methods bring private variables out
Julia item to get song name is our access or
method Making it private would make it possible to access
song ing item three hour print function Well it'll also
needed to use definitely should not be driving That means
only item one should be private and our answer will
be a but wait why even use successor methods at
all Couldn't we just make strings public Then we could
read from them any Time from anywhere in the program
without having a father with access or method Well that's
true there's no law against it But doing things this
way is the best practice gives us what's called an
abstraction layer well imagine this You've written a huge programme
and in various places throughout your accessing variables directly Well
values were getting changed over here accessed over here Change
down there it's bedlam way have mutate er methods so
that users can't change data any which way they want
you taters finally all the request to change data for
one checkpoint and make sure users are not changing data
in a bad way Blacks esther's you're just annoying repercussion
of using mutated by making variables private and edited on
ly through mu taters we essentially lock off all access
to the variables Thus we need access er's toe let
users get the values of the private variables Tons have
overkill for a simple project where you keep track of
a playlist well maybe but it's a good habit tohave
And when your simple project balloons into an enterprise level
canoe related media organizational solution well you'll be glad it's 00:02:27.51 --> [endTime] there