150 likes | 533 Views
Encapsulation and Connascence. Encapsulation and connascence are the two fundamental properties of object-oriented systems Present in both traditional and object-oriented systems Encapsulation Structure connascence. Encapsulation. Original Meaning
E N D
Encapsulation and Connascence • Encapsulation and connascence are the two fundamental properties of object-oriented systems • Present in both traditional and object-oriented systems • Encapsulation Structure • connascence
Encapsulation • Original Meaning • grouping of related ideas into one unit • can be referred to by a single name • Existing Concept in Software Design • repeating pattern in programs • subroutine • Object-Oriented Encapsulation • packaging of operations and attributes • become an object type • access attributes only via object interface
Encapsulation Structure • Subroutine • introduce encapsulation to software • encapsulate lines of code into a structure one level higher • Levels of Encapsulation • Level 0 - raw code (no encapsulation) • Level 1 - subroutine • Level 2 - object • Higher Levels - grouped classes • Concept of Classes improves reusability
Encapsulation by Grouping Classes • Horizontal Group • grouping by respective subject area • comprises classes from the same domain • packages • Vertical Group • grouping by business activity • usually come from several domains • components
Design Criteria for Encapsulation • Traditional Structured Design vs. Object-Oriented Design • Criteria for interacting levels • structured programming - line to line • fan-out - reference to other procedures • cohesion - connection within procedure • coupling - connection between procedures • class cohesion - connection within class • class coupling - connection between classes
Connascence • Original meaning - born together • Interdependence, Coupling • Definition of Connascence in Software • Varieties of Connascence • Contranascence • Connascence and Encapsulation Boundaries • Connascence and Maintainability • Connascence Abuses in O-O Systems
Connascence in Software • Connascence between software elements A and B • change in A requires B to be changed • A and B need to be changed together • Software element needn’t communication in order to connascent • Connascence can be directional or nondirectional
Static Connascence • Applied to the code of classes • Connascence of Name • variables in procedures or in classes • Connascence of Type or Class • types in declaration • Connascence of Convention • same constraints for several elements • Connascence of Algorithm • similar to connascence of convention • Connascence of Position • sequential, adjacent, argument order
Dynamic Connascence • Based on the execution pattern of the running code (objects) • Connascence of Execution • dynamic equivalent of connascence of position • Connascence of Timing • mostly in real-time systems • Connascence of Value • arithmetic constraints • Connascence of Identity • object reference
Contranascence • Connascence of Difference • Negative Connascence • Mostly Contranascence of Names • Specially Important for Multiple Inheritance
Connascence and Encapsulation Boundaries • Object orientation eliminates some of the connascence in traditional modular systems • Encapsulatio is a check on connascence and contranascence
Connascence and Maintainability • Offers guidelines for improving system maintainability • Minimize overall connascence and contranascence => encapsulation • Minimize any remaining connascence that crosses encapsulation boundaries • Mazimize connascence within encapsulation boundaries
Connascence Abuses in Object-Oriented Systems • The friend function of C++ • violate encapsulation boundaries • Unconstrained inheritance • introduce raging connascence • Relying on accidents of implementation • ex. connascence of algorithm