Browse Prior Art Database

Simple Way to Define Many Classes of a Type as Friends of a Class

IP.com Disclosure Number: IPCOM000111960D
Original Publication Date: 1994-Apr-01
Included in the Prior Art Database: 2005-Mar-26
Document File: 4 page(s) / 55K

Publishing Venue

IBM

Related People

Lunia, PS: AUTHOR

Abstract

Disclosed is a simple way to define classes of a type as friends of a class.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 54% of the total text.

Simple Way to Define Many Classes of a Type as Friends of a Class

Disclosed is a simple way to define classes of a type as friends of a
class.

      In object-oriented programming, sometimes there is a necessity
to declare some kind of classes (derived concrete classes from a base
class) as a friend to some class X. This requires each concrete class
to be declared as a friend of the class X.

      Exemplary Code

This is what the C++ code looks like.

// Base class
   class Base {
   public:
    virtual void f() { doSomeThing; }
    virtual void g() { doSomeThingElse; }
   private;
    int g;
    int f;
   };

// Derived classes - derived from Base
class A : public Base {

 // some code
};

// another class
class B : public Base {

 // some code
};

// another class

class C : public Base {
  // some code
};

// another class
class D : public Base {

 // some code

};

// class X
class X {
public:
  friend class A;
  friend class B;
  friend class C;
  friend class D;
  // so on.

private:
  int a;
  char b;
  short c;
};
// The example shown above shows the list of friend declaration need
to
// be made into class X.
// Now when we want to add a new class E we will have to change the
// class X.
class E : public Base {
  // some code
};
// class X will change
class X {
public:
  friend class A;
  friend class B;
  friend class C;
  friend class D;
  friend class E;
  // so on.
private:
  int a;
  char b;
  short c;
};

From the example one can see that additional derived classes will
cause the class X code to be modified....