   hide protected/private class members from the user, COM?
  Hello everyone,I've been working on my directX wrapper for a while, and i'm using oop, but, as you know, the classes/structures are defined in header files, which can be seen by the user(yes, they cant use them, but those members pretty much shows what the class code looks like), what if i want to hide them? i assume i should use COM? well what is COM? is it what i'm looking for? any recommended sites for learning it's basics?is it hard and time consuming to convert my code to fit with COM?Thanks for your time   
  Why do you assume you can use COM if you don't know what it is? You're probably looking to use the pimpl idiom here.   ;Quote:Original post by DaveWhy do you assume you can use COM if you don't know what it is?because Direct3D uses COM (i've read this in many books), and i can't see contents of their structs[/classes], all i see is a bunch of COM stuff, and thus, i assumed it's what i'm looking for   ;  There are different approaches which work. Two very common ones are:1. Pimpl2. Interface and Factory (aka "COM")Example for Pimpl:[source language="c++"]class Black_Box {  public:    // Creates Black_Box_Impl object    Black_Box();    // Destroys Black_Box_Impl object    ~Black_Box();    // TODO: You also need a copy constructor and assignment operator    // TODO: which copy the implementation object.    // TODO: (Or you can make your class noncopyable)    // A method which is visible to the user    // Does stuff with Black_Box_Impl object    void some_method();    private:    // Implementation (details hidden from user)    Black_Box_Impl* pimpl;};Example for Interface and Factory:[source language="c++"]class Interface {  public:    // A method which is visible to the user    virtual void some_method() = 0;};// Factory.// Creates an object and returns an interface to it.// Details about the object are hidden from the user.Interface* create_black_box();The interface pattern is more flexible, because interfaces are completely decoupled from objects. The user does not know how many and what kind of objects there are, unless this information is made available through the interfaces. This gives the developer of the implementation classes a lot of freedom in designing the implementation and modifying the design later.The disadvantage of using interfaces is that it is less convenient when it comes to object creation and memory management. To create an object, the user must use a factory. Memory management is typically done using reference counting (see COM's IUnknown interface), which requires smart pointers to be safe.With the Pimpl idiom, the user can create objects directly and choose the memory management strategy himself, which is more natural. In fact, the user doesn't even need to know you are using Pimpl.   ;  I dont get both of them, first one, what is Black_Box_Impl? another structure that hold the private data? wouldnt it be also seen as a structure? i dont see the pointand at the interface, i dont really get anything from it, create_black_box is a pointer to an Interface, what does it have to do with hiding private/protected members?   ;  I think what you're missing is that you don't have to have a fully defined class to create a pointer to that class.  You also don't have to define classes in public headers.The pimpl idiom takes advantage of this.  You do something like this in your public header:class Impl;    // class Impl is defined somewhere elseclass Foo{    Impl * impl;   // but you can still make a pointer to it};Then you put the definition of Impl in a private header (or not in a header at all).   ;  what if a friend class of foo wants to access impl member (assuming it's protected), i think the friend of foo won't see the definition of impl, am i right? ( ahh..it's somewhat confusing for me )Well, what about COM? i really want to learn about this technology, i dont see any helpful tutorials on the net, anyone can point me to the right direction?   ;Quote:Original post by HassanbasilWell, what about COM? i really want to learn about this technology, i dont see any helpful tutorials on the net, anyone can point me to the right direction?COM is a technology from 1993. It's obsolete for all purposes, unless you happen to find yourself in a job maintaining 15 year old codebases.Quote:but those members pretty much shows what the class code looks likeWhy would anyone care about that...Quote:any recommended sites for learning it's basics?COM is one of technologies which was several orders of magnitude more complex than C++ language. There is nothing simple about it, Hello World example was hundreds of lines and tens of files.COM was essentially precursor to reflectable managed languages, but without convenient language to expose it, so it would be like trying to write Java using JVM source code.   ;Quote:Original post by Hassanbasilwhat if a friend class of foo wants to access impl member (assuming it's protected), i think the friend of foo won't see the definition of impl, am i right? ( ahh..it's somewhat confusing for me )Well, what about COM? i really want to learn about this technology, i dont see any helpful tutorials on the net, anyone can point me to the right direction?Put the definition of Impl in a header that's shared between the code for the outer class and the code for the friend.  This header is not shared with the general public.COM is basically the same thing with some extra stuff tacked on.  If you don't understand this stuff then COM isn't going to be any easier.  Another term you can study up on is "forward declaration".   ;What is COM?MSDN - Programming DirectX with COM---Quote:Original post by AntheusIt's obsolete for all purposes, unless you happen to find yourself in a job maintaining 15 year old codebasesI think this is a little extreme.  If you don't want to use a managed language and still use DirectX, your probably going to end up using COM.   