Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 HomeCADEngine 外观类中,我有一个方法“addRoom(room:Room)”,它会将这个房间添加到 ArrayList。但是,当我们在外观类之外创建一个房间然后将其传递给 addRom() 方法时,它是否打破了外观模式?
非常感谢
这取决于,模式只是改进代码的指南。在这种情况下,如果您在外观内创建 Room 并且您无法从外观类之外的任何其他类访问 Room 类,即使创建新的 Room 实例,也会更准确。
重要的是外观模式的目的是封装对其他/s类的所有访问,并且对它们的每次访问都必须通过外观类。