The Pain of OOP, Lecture #3: Getters and naked data [object oriented programming crash course]

preview_player
Показать описание
A lecture for BSc students in Innopolis University.

0:00 Lecture description
2:36 What is a Getter
8:25 Boilerplate
10:55 Purpose
17:25 Data Transfer Objects (DTO)
26:53 Encapsulation
41:15 Integrity
50:22 Semantic
1:06:26 The Alternative. TellDontAsk
1:10:17 NoPrefix
1:14:55 Read and Watch
1:16:00 Spring Framework
Рекомендации по теме
Комментарии
Автор

Yegor thank you for sharing your experience and knowledge.

useyourimagination
Автор

I’m almost done with my demonstration implementation of your ideas, I just have to convert my domain object exercise code to tests

It’s based on a fork of your jpages project repo

ChrisAthanas
Автор

Thank you from South Korea. Always inspiring🙌

kangthink
Автор

on 47:50, so if i am not mistaken, this user class became a facade for Employment and Salary classes right?

nikolozlatsabidze
Автор

Well .... A setter could screen data for validity, but getters are kinda funky. If you want good encapsulation, plain ol' C had opaque pointers. I like those.

kayakMike
Автор

Thank you for the excellent lectures, Yegor! Your blog is very insightful, as are your books - I've read most of them!

What do you think about the Go language and its philosophy? It doesn't position itself as an OOP or functional language.
Yet it has structs with methods, first-class functions, and interfaces that are satisfied implicitly.
Go encourages package-oriented design for code organization.
There are no classes or constructors, no inheritance, no method overloading, no interface fields and default methods.
Would you say the principles of Elegant Objects could still be helpful with how we design types with behavior?

mtlkldw
Автор

Are you still working on Eolang?
You have not made a video about it since 2 years ago.

encapsulatio
Автор

Only 3 fields? What about users with id, first name, last name, middle name, login, email, phone, some descriptions and boolean fields, for example?

viktor_the_developer
Автор

i always was wondering how is it we are hiding or encapsulating data if we can set get or modify them. Encapsulation is a discipline not a mechanism - i like that definition. and avoid them at all that is what i was looking for for a long time

farrukhjonnazriev
Автор

Thanks for lecture. I’ve always had this feeling that something is wrong with main-stream OOP, so trying to understand it better from your content.

What are your thoughts on clean-arcitecture and modern data-driven UI frameworks(like SwiftUI, Compose, React)? It feels like they also go against data encapsulation and into more procedural way of writing code. So each layer should have all the data available for next layer in order to format or render it.

If we don’t want to expose inner structure and raw data from object, should this object itself be responsible for rendering itself on screen?

alex.oleynyk
Автор

Вопрос про getText для сообщения от телеграма хороший, но с ответом я не согласен. Как можно предусмотреть, что человек будет делать с информацией, если вы делаете открытую библиотек, он может как вывести ее, так и записать в бд. Или захотеть найти в сообщении ключевые слова. Для всего этого не предусмотришь методов заранее.
Еще вопрос: в каких местах без геттеров нельзя обойтись? То есть когда можно оставлять поле класса публичным?
Спасибо за лекцию, 2 предыдущие прям огонь были, после этой немного непонимания и вопросов

StudentVlogs
Автор

Make fields public: in 90% cases DTO is readonly, values sets by constructor and there are getter only.

andreylebedev
Автор

Я так пока и не уловил, как объект вместо излучения данных из себя делает что-то, что от него хотят другие, он не может предугадать что от него захотят другие. В примере с коробкой и весом проблема в языке программирования, в котором слабая система типов. В том же голанг делаешь типы lbs(uint) и kg(uint) и проблема решена. И в данном языке приемами ооп можно выкрутиться – также сделать DTO Kg и Lbs с единственным методом getValue(), а метод Box.GetWeight() будет возвращать объект Kg или Lbs.

andreylebedev
Автор

Hey, what if that DTO had some validation built-in to the initialization? Is that enough behavior?

kayakMike
Автор

In fact, lots of code in both Linux and Git is in fact object-oriented (in some sense, at least): they have virtual method tables, interfaces and so on. Maybe it's not exactly what you're promoting, but that's not less object-oriented than some of the bad examples written in Java that you show.

АдамСмит-ыр