56.3k views
0 votes
Is class pollution where a class knows more information than it needs to?
a. Yes
b. No

User Coolhand
by
8.3k points

1 Answer

4 votes

Final answer:

Class pollution refers to a class in object-oriented programming having access to more information than it needs to perform its functions, leading to poor design and complexity. The principle of least knowledge suggests that a class should only know what is necessary for its duties.

Step-by-step explanation:

The question of whether class pollution is where a class knows more information than it needs to can be answered with a Yes. This concept is known as information overload or class pollution in object-oriented programming. The term describes a situation where a class has access to more data than it requires to perform its functions, which can lead to poor design, reduced maintainability, and increased complexity of the code. A well-designed class should adhere to the principle of least knowledge, also known as the Law of Demeter, which states that a class should only interact with its immediate friends and not strangers, hence knowing only the information that is necessary to fulfill its responsibilities.

User Atul Goyal
by
8.1k points

No related questions found