DAY 12
πΒ μ€λ μ½μ λ²μ : 6μ₯
<aside>
π μ±
μμ κΈ°μ΅νκ³ μΆμ λ΄μ©μ μ¨λ³΄μΈμ.
</aside>
- Hiding implementation is not just a matter of putting a layer of functions between the variables. Hiding implementation is about abstractions! A class does not simply push its variables out through getters and setters. Rather it exposes abstract interfaces that allow its users to manipulate the essence of the data, without having to know its implementation.
- We do not want to expose the details of our data. Rather we want to express our data in abstract terms.
- Objects hide their data behind abstractions and expose functions that operate on that data. Data structure expose their data and have no meaningful functions. [Listing 6-5]
- Procedural code (code using data structures) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions.
- Procedural code makes it hard to add new data structures because all the functions must
change. OO code makes it hard to add new functions because all the classes must change.
- Mature programmers know that the idea that everything is an object is a myth. Sometimes you really do want simple data structures with procedures operating them.
- The Law of Demeter:
The method should not invoke methods on objects that are returned by any of the allowed functions. In other words, talk to friends, not to strangers.
- ...If they are objects, then their internal structure should be hidden rather than exposed, and so knowledge of their innards is a clear violation of the Law of Demeter. On the other hand, if they are just data structures with no behavior, then they naturally expose their internal structure, and so Demeter does not apply.
- The quintessential form of a data structure is a class with public variables and no functions. This is sometimes called a data transfer object, or DTO. DTOs are very useful structures, especially when communicating with databases or parsing messages from sockets, and so on. Somewhat more common is the βbeanβ form.
<aside>
π€ μ€λ μ½μ μκ°μ? λ μ€λ₯΄λ μκ°μ κ°λ³κ² μ μ΄λ³΄μΈμ
</aside>
I did learn in my bootcamp that everything is an object. π
<aside>
π κΆκΈν λ΄μ©μ΄ μκ±°λ, μ μ΄ν΄λμ§ μλ λ΄μ©μ΄ μλ€λ©΄ μ μ΄λ³΄μΈμ.
</aside>
<aside>
π‘ μκ° 3μ€ μμ½
</aside>
- Objects expose behavior and hide data:
This makes it easy to add new kinds of objects without changing existing behaviors. It also makes it hard to add new behaviors to existing objects.