CS 101: Differences between Private and Protected
What's going on Youtube,
So in today's video, we will discuss the difference between private and protected properties. This is a common question that I tend to ask interns just to see if they understand the basics of object oriented programming. While most candidates will get this question right, there will be a few that do not know.
I think that a good way to understand the differences will be to use a live example. So a few things that I want to present to you is an example of protected and private properties and why we use them.
What we have before us is a code sample that we will use to show the difference between private and protected properties. The class "Car" has the private property "vin" which is assigned to a random number. The class, "Nissan" extends from "Car" and assign the value "Nissan" to the property "make" whenever the object is created.
One thing we know about private properties is that it is only accessible by the class that it is in. Meaning that the class "Nissan" cannot see the property "vin".
One thing we know about protected properties is that it is only accessible by the class that it is in, and other classes that extends it. Meaning that the class "Nissan" can see the property "model" and "make".
If the class "Nissan" want's to access the private property "vin", then it needs to use a method that will give use that information.
When it comes to the reason behind using private and protected properties, lets just say that there is an endless list. The most common reason why developers use private and protected properties is to prevent them from being accessed improperly. Another reason why is that they are helper methods and should only be used within the class. One thing you may be wonder is: "When should I use private or protected properties?" Since the answer depends on your project, I can give you 3 short rules to remember
- All getter and setter methods, should be public.
- All class variables should be either protected or private
- All helper method should be protected
#Music#
By Nsolo
- YouTube: https://www.youtube.com/channel/UCW-0lRDctPW1JtjgIn-vCzA
- SoundCloud: https://soundcloud.com/nsolo
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «CS 101: Differences between Private and Protected», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.