Behavioral compositions, groups of interdependent objects cooperating to accomplish tasks, are an important feature of object-oriented systems. This paper introduces Contracts, a new technique for specifying behavioral compositions and the obligations on participating objects. Refinement and composition of contracts allows for the creation of large grain abstractions based on behavior, orthogonal to those provided by existing class constructs.Using contracts thus provides a basis and vocabulary for Interaction-Oriented design which greatly facilitates the early identification, abstraction and reuse of patterns of behavior in programs.Contracts differ from previous work in that they capture explicitly and abstractly the behavioral dependencies amongst cooperating objects. By explicitly stating these dependencies, contracts also provide an effective aid for program understanding and reuse.sizing and reshaping operations with its child windows to ensure that it always properly surrounds them. Patterns of communication within a behavioral composition are often repeated throughout a system with different participating objects. They represent a reusable domain protocol or programming pasadigm. For the purposes of extending, modifying or re-using programs, it is clearly important to understand these behavioral compositions and the inter-object dependencies they imply.
We introduce a simple, programming language independent rule (known in-house as the Law of DcmeterTM) which encodes the ideas of encapsulation and modularity in an easy to follow form for the object-oriented programmer. You tend to get the following related benefits when you follow the Law of Demeter while minimizing simultaneously code duplication, the number of method arguments and the number of methods per class: Easier software maintenance, less coupling between your methods, better information hiding, narrower interfaces, methods which are easier to reuse, and easier correct.ness proofs using structural induction. We discuss two important interpretations of the Law (strong and weak) and we prove that any object-oriented program can be transformed to satisfy the Law. We express the Law in several languages which support object-oriented programming, including Flavors, Smalltalk-80, CLOS, C++ and Eiffel.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.