#LậpTrình #KiếnTrúcPhầnMềm #CSharp #Encapsulation

Phần 4: Encapsulation & Designing for Ignorance

Đừng hiểu sai encapsulation chỉ là "private fields + getters/setters". Đó là cơ học.

Encapsulation thực sự là về **epistemic**: Ai được phép biết gì và ai cần bị… làm ngơ.

Mỗi thông tin bạn expose ra ngoài là một dependency, một rủi ro coupling. Encapsulation tồn tại để giới hạn sự lây lan kiến thức này, giúp hệ thống có thể refactoring và phát triển độc lập.

Hãy xem ví dụ về `Order`:
❌ Sai: `p

停止错误地将对象当作数据容器!掌握“Tell, Don’t Ask”原则:别问对象要数据,而是告诉它该做什么。这样能提高封装性、减少重复代码,让逻辑更清晰。举例说明,Shop 类不应直接操作 Account 的余额,而应调用 account.canAfford() 和 account.withdraw() 让 Account 自己处理。这样写更符合面向对象设计。

#OOP #Programming #TDA #Encapsulation #CodeQuality #LậpTrình #ThiếtKếPhầnMềm #TốiƯuMã #LậpTrìnhHướngĐốiTượng #NguyênTắcLậpTrình

https://dev.to/jonghwayoo03_dev/stop-asking-for-data-master-the-tell-dont-ask-principle-373g

Stop Asking for Data! Master the "Tell, Don't Ask" Principle

One of the most common mistakes in Object-Oriented Programming (OOP) is treating objects like simple...

DEV Community

Private Fields Use # Symbol?!

Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!

#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript

https://www.youtube.com/watch?v=ycxs4Sb_7Eo

Private Fields Use # Symbol?! #codingchallenge

YouTube
Brent’s Encapsulated C Programming Rules

A bunch of tips and rules I’ve created for myself for developing programs in the C programming language

Brent’s Website

After thought (thought I didn’t plan to put into it), I don’t think "NULL coalescing" and "NULL chaining" needs to be built in to the #ProgrammingLanguage, and here’s why:

* If you’re getting just one thing, the getter can take an optional default result value. #Python works like this in `getattr`, `.get`, and things of that nature. Having an operator for this is fine, but it seems obvious you don’t **need** the language to do it for you.
* If you’re walking down a long uncertain chain, I have two arguments:
* Knowing the path that leads down into the object to the specific thing you want kinda sounds like an #Encapsulation violation. Why do you know so much about the internals of this object. If this deep property is important, maybe it’s part of the interface of the top-level thing. Maybe this is just bad design.
* Diving deeply involves lots of possibilities: possible defaults, actual methods of finding the named thing (allow inheritance? Is it an attribute? Is it an element of an array? Etc), did you want to just stop or raise an exception?Does saying what you want really come out to a simple, clean, understandable, one-line, expression?

Maybe I’m biased because I don’t have these operators in my day-to-day language; and also can’t remember hitting this situation. And I can certainly see such operators could be helpful. I’m not a language designer. But from my actual experience, in this case, the juice just isn’t worth the squeeze.

#NullCoalescing #NullChaining #LanguageDesign

Một bài viết từ /u/EgregorAmeriki thảo luận về đóng gói (encapsulation) trong lập trình không cần dùng từ khóa private, thay vào đó áp dụng thiết kế dựa trên giao diện (interface-based design) để tối ưu tính bảo mật và tính linh hoạt của code.

#Lập_trình #Object_Oriented #Design_Pattern #Công_nghe #Thiet_ke_phan_mem #Programing #OOP #SoftwareDesign #Encapsulation #InterfaceDesign

https://www.reddit.com/r/programming/comments/1o934q9/encapsulation_without_private_a_case_for/

📜 Behold, a relic from the distant past—2013! Back when "Page Object" was the new black in the world of #testing, because clearly, nobody knew that UIs change. 🤯 Marvel at the revolutionary idea of not frying your tests with a side of HTML spaghetti, as if #encapsulation wasn't already a thing. 🍝
https://martinfowler.com/bliki/PageObject.html #HackerNews #PageObject #HTMLSpaghetti #UITrends #HackerNews #ngated
bliki: Page Object

A page object wraps an HTML page, or fragment, with an application-specific API, allowing you to manipulate page elements for testing without digging around in the HTML.

martinfowler.com
Getting that I have themes on encapsulation and threads #nsfw #nude #encapsulation #cocoon #strings #naked #nudephotography #photography #photo #silentsunday

quotes from the text:

"The concepts rejected as “not complex enough” might be simple building blocks, like molecules in a living body, that can be combined with other concepts to create a framework that can handle an adequate amount of complexity."

"I.e. that the black box has only the purpose of simplification and not that of knowledge elitism and hidden power structures."

#ComplexSystems #Encapsulation