Coding Interview Questions: Differences between Class and Instance Methods
In this guide I'm going to cover one of the popular coding interview questions: "What are the differences between class and instance methods". In addition to discussing the differences at a high level I also give examples of when and how the two types of methods should be used in a production application.
I'm a Ruby developer and this episode's answer will be addressed from the Ruby perspective, however it's a concept that can be important to know in other languages as well, for example Objective C and Java have class and instance method options.
So what do you do when the interviewer asks the difference between class and instance methods?
From a practical perspective a class method can be called by itself, for example, if you had a class that handled sending SMS messages, you could call the class method by itself and simply pass in the values that you want to send in the SMS message.
An instance method is a function that requires an instance of the class to be created. In the SMS example we didn't need to create an SMS instance, we only cared about the system sending the text message. An example of an instance method would be something like a full name method in a Customer class. If you want to know the full name of a customer you most likely have a customer in mind and Already instanciated the class into an object with a specific Customer selected.
In summary, I typically use instance methods since I'm usually calling methods on objects, class methods are helpful from time to time, but in many cases they can be a sign of poorly constructed code since many class methods could be refactored into modules and out of classes.
Follow me:
Twitter: https://twitter.com/jordanhudgens
Instagram: https://www.instagram.com/jordanhudgens/
GitHub: http://github.com/jordanhudgens
Full guide:
https://www.crondose.com/2016/04/programming-interview-question-differences-between-class-and-instance-methods/
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Coding Interview Questions: Differences between Class and Instance Methods», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.