Skip to main content
GameDev.net gamedev.net
🔒 Locked

Interfaces

Started by peckerpeck May 15, 2003 at 4:28 PM 6 replies 600+ views
Original Post
peckerpeck
peckerpeck
I have a small class with less than 10 routines in it. However, about 4 I only want accessed by object A, and the remaining ones I want only accessed by object B. What is the cleanest OO solution? Split the object in 2? Seems like too much overhead. Make 2 structs in the object with function ptrs as interfaces? Just get over it and let object B call routines only meant for object A? Ack!
rypyr
rypyr
The first Anonymous Poster got it right. You need to use "interfaces" (in the Java sense). It''s funny that your topic title holds the answer. An interface is an abstract base class that consists of only pure virtual methods (and usually no data members).

Then your "small class" which provides those methods "implements" that interface by having the interface class as a base class.

Regards,
Jeff

peckerpeck
peckerpeck
The only thing with this approach is that main still has access to SmallClass s.

Also, while I''m writing, I don''t quite get what the invoke () method is doing


  
void invoke() { m_x->func1(); m_x->func4(); }


And did you leave out func2 and func3 just b/c you were tired of typing?
civguy
civguy
quote:
Original post by peckerpeck
And did you leave out func2 and func3 just b/c you were tired of typing?
Apparently. They don't all *need* to be invoked. It was just a demonstration of what can be invoked. The invoke()-method does essentially nothing interesting. It's just a normal member function like any of your member functions. An example of a one.

[edited by - civguy on May 20, 2003 3:45:19 AM]
Way Walker
Way Walker
How about


class SmallClass {

public: // Only meant for use in instances of class A
void func1();
void func2();
void func3();
void func4();

public: // Only meant for use in instances of class B
void func5();
void func6();
void func7();
void func8();
void func9();
void func10();

}; // class SmallClass


?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.