0

I am thinking of creating OOP model of "REQUEST TRACKER".

So, I thought the following:

Parent Class: RequestOrResponse (containing common fields of Request and Response such as ID, date, item involved, user, quantity).

Child Classes: 1. Request (with data members: priority, status, remaining quantity), 2. Response (with data member relatedRequest)

Response class has a data member which is an object of Request.

Curious
  • 127
  • 3
  • 11

2 Answers2

0

Yes; there's no general reason why this should not work.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
0

Yes, and not only that. An object may also "contain" an object of its own class.

That's because it's not actually an object it contains, but a reference to an object, so it won't need infinite space.

Squirrelkiller
  • 2,575
  • 1
  • 22
  • 41
  • Whether "an object" equals "a reference to the object" actually depends on the programming language. And if not, you might not be able to reference it in its own definition, because, well, it's still being defined. In C++ for example, you can't even compile `class A{ public: A a; };`, because `field 'a' has incomplete type 'A'`. You'd need to make `a` a pointer. – Siguza Jul 11 '15 at 15:34