SDSU CS 696: Advanced OO
Spring Semester, 1997
Doc 7, Demeter part 2

To Lecture Notes Index
San Diego State University -- This page last updated Feb 25, 1997
----------

Contents of Doc 7, Demeter part 2

Strict form using Classes For C++slide # 2
Some Comments By the Creators slide # 4

Doc 7, Demeter part 2 Slide # 1
Reference

Lieberherr and Holland, Assuring Good Style for Object Oriented Programs, IEEE Software, pp 38-48, Sept. 1989

Lieberherr, Holland, Riel, Object-Oriented Programming: An Objective Sense of Style, OOPSLA 1988 Proceedings


Doc 7, Demeter part 2 Slide # 2
Law of Demeter

Strict form using Classes For C++


In all member functions, M, of class, C, you may only use members (function and data) of the following classes and their base classes:


Doc 7, Demeter part 2 Slide # 3
C++ Example
class A
     {
     public: 
          B data;
          B* moreData;

          B safeGet() { return data; }
          B* get() { return moreData; }

          A() { moreData = new B(); }
     }

class C
     {
     private:
          A myData;

     public:
          void M1() {       A.data.message(); }

          void M2() {       ( new B() )->message(); }

          void M3() {       A.safeGet().message(); }

          void M4() {       A.get()->message(); }

     }

Doc 7, Demeter part 2 Slide # 4

Some Comments By the Creators


"In some situations, the cost of the obeying the strict version of the law may be greater than the benefits"


"In general, if the application concepts are well defined and the class that implement those concepts are stable, such violations are acceptable"
----------