ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos

AP Computer Science 3.1 Classes and Objects 187 Views


Share It!


Description:

In this computer science problem, which of the following should be declared as private?

Language:
English Language

Transcript

00:00

Sorry And here's your shmoop douceur brought to you by

00:05

canoe jokes can new jokes or you kidding me Which

00:15

of the following should be declared His private song name

00:18

gets on name prince We're writing a class called paddling

00:26

songs to keep track of a killer paddling playlist and

00:29

we're being asked which bits should be declared private Well

00:33

i don't want bring song name being that we're writing

00:36

an access or method called get song name specifically teo

00:39

get data from song name the string song name should

00:42

indeed be private things like this A private variable is

00:45

like your friends Your friend is overprotective of her kat

00:48

so she doesn't let anyone see it or pet it

00:51

However if you want your friend will bring the cat

00:54

out of the house and let you see it pet

00:56

It will bring the cat out whenever you ask her

00:58

to just his access Her methods bring private variables out

01:02

Julia item to get song name is our access or

01:05

method Making it private would make it possible to access

01:09

song ing item three hour print function Well it'll also

01:12

needed to use definitely should not be driving That means

01:15

only item one should be private and our answer will

01:18

be a but wait why even use successor methods at

01:21

all Couldn't we just make strings public Then we could

01:24

read from them any Time from anywhere in the program

01:27

without having a father with access or method Well that's

01:29

true there's no law against it But doing things this

01:32

way is the best practice gives us what's called an

01:34

abstraction layer well imagine this You've written a huge programme

01:38

and in various places throughout your accessing variables directly Well

01:42

values were getting changed over here accessed over here Change

01:45

down there it's bedlam way have mutate er methods so

01:49

that users can't change data any which way they want

01:51

you taters finally all the request to change data for

01:55

one checkpoint and make sure users are not changing data

01:58

in a bad way Blacks esther's you're just annoying repercussion

02:02

of using mutated by making variables private and edited on

02:06

ly through mu taters we essentially lock off all access

02:09

to the variables Thus we need access er's toe let

02:12

users get the values of the private variables Tons have

02:15

overkill for a simple project where you keep track of

02:18

a playlist well maybe but it's a good habit tohave

02:20

And when your simple project balloons into an enterprise level

02:23

canoe related media organizational solution well you'll be glad it's 00:02:27.51 --> [endTime] there

Up Next

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

Related Videos

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?