The main goal (almost not evident) of design (from a low-level perspective) is to minimize coupling and maximize cohesion.
COUPLING:
Coupling is the level of interdependency between a method and the environment, (other methods, objects and classes), while cohesion is the level of uniformity of the method goal. While coupling needs a low-level perspective, cohesion needs an higher point of view. All patterns tends to reach these two objectives. Exactly knowing DP goals, we can more correctly apply the Design Patterns, apply one of it without knowing nothing about it and, perhaps, try to invent another one.
Coupling
To low coupling tends to create more reusable methods. Obviously this is only a trend, because it's not possible to write completely decoupled methods, or the program will not work!
COHESION:
A method is cohesive when it does only a single, precise task, but not at low level of abstraction like in coupling. At low level methods perform input, execute commands, do something. At an higher level they perform "tasks", like "clone" or "print", on other objects or on local members: so a method "clone an object", "print a report", etc. The more the method is focused on a single goal like clone(Object obj) or print(Report r), the more it will cohesive.An high cohesion method will be simpler to understand, having to do only a single task, while a low cohesion method, performing so many tasks, will be difficult to follow in application logic
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment