Thread: Information Hiding

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    115

    Information Hiding

    I somehow understand what a library is in computer programming.
    Library is a collection of subroutines or classes to provide services on creating an application.

    I read these paragraphs and wasn't able to understand
    what it means about C language struct and the problem experienced in it.

    Code:
    1st Paragraph
    Many of these libraries manipulated data in the form of open record data-structures, 
    such as the C-language struct. The main problem with record structures is that the 
    library designer cannot hide the implementation of the data used in the procedures. 
    This makes it difficult to modify the implementation of the library without affecting the 
    client code because that code is often tied to the particular details of the data structures.
    
    2nd Paragraph
    By the late 1980s, object-oriented programming (OOP) became popular with C++. 
    One of the greatest advantages of OOP was the ability to hide certain aspects of 
    a library's implementation so that updates do not affect client code( assuming the 
    interfaces do not change). The other important advantage is that procedures were 
    associated with the data structure. The combination of data attributes and procedures
    ( called methods ) are known as a class
    1st Paragraph question
    The implementation of the data used in the procedures cannot be hidden
    by the library designers is because C does not use the object-oriented programming
    feature if I'm not wrong.

    Updating a library is just downloading the library and putting it in your lib folder?

    Why is it difficult to modify the implementation of the library without affecting the client code?

    What is a client code anyway?-is it the software that was created using the library?

    How is it going to affect the client code?


    2nd Paragraph question
    I understand how the implementation and the interface is separated using C++.
    I also understand how the implementation is hidden using C++. So if C++ does
    have the capability to hide the implementation of the library does it mean that
    modifying or updating the library implementation is not gonna be difficult and it's
    not going to affect the client-code ( not unless if the interface is changed )?

    How is it not going to affect the client-code?
    =====================================
    Sorry for so many questions but if you can give me a good link about what I'm
    asking here I would be glad to read it.


    thanks.
    Last edited by $l4xklynx; 06-23-2009 at 08:46 AM. Reason: post rearranged.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by $l4xklynx
    The implementation of the data used in the procedures cannot be hidden
    by the library designers is because C does not use the object-oriented programming
    feature if I'm not wrong.
    No, it can be hidden, e.g., by providing a pointer to a structure that is the implementation of the library module. So, a set of functions that take such a pointer as an argument are provided, but in the header, only a forward declaration of the structure type is needed. Consequently, the structure can be changed at will in the relevant source file, with the implementation being hidden.

    Updating a library is just downloading the library and putting it in your lib folder?
    In this context, it means changes to a library implementation as made by a maintainer of that library.

    Quote Originally Posted by $l4xklynx
    Why is it difficult to modify the implementation of the library without affecting the client code?
    Because the client code could be relying on exposed implementation detail, hence changing the implementation could result in the client code relying on something that is no longer the same, or even no longer exists.

    Quote Originally Posted by $l4xklynx
    What is a client code anyway?-is it the software that was created using the library?
    Yes, the source code that uses the library.

    Quote Originally Posted by $l4xklynx
    How is it going to affect the client code?
    Bugs may be introduced due to mistaken or unwarranted assumptions when relying on the implementation detail, or the client code may simply fail to compile.

    Quote Originally Posted by $l4xklynx
    So if C++ does
    have the capability to hide the implementation of the library does it mean that
    modifying or updating the library implementation is not gonna be difficult and it's
    not going to affect the client-code
    Actually, what C++ implements is more like access restriction than actual hiding. Actual hiding can be achieved with the same pointer to the implementation (pimpl) approach as I outlined earlier. Consequently, the library maintainer can freely change the implementation of a well designed class, but it may be the case that client code must be recompiled if the pimpl idiom is not used.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by laserlight View Post
    No, it can be hidden, e.g., by providing a pointer to a structure that is the implementation of the library module. So, a set of functions that take such a pointer as an argument are provided, but in the header, only a forward declaration of the structure type is needed. Consequently, the structure can be changed at will in the relevant source file, with the implementation being hidden.
    I understand most of the answers that you provided but this one. let's say:

    Code:
    |Library | <-- where the pointer to a structure is etc.
    struct A {
      //statement....
    };
    typedef A *alibrary;
    
    
    |Header| <-- forwarded declaration of the structure type
    alibrary aheader
    
    |.C file| <-- #include the Header
    The graphical representation I created above is how I understood your statement above-is that what you actually mean?

    The library and the header they could be of different file how are they able to communicate to each other? through the linker?


  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by $l4xklynx
    The graphical representation I created above is how I understood your statement above-is that what you actually mean?
    Roughly, yes. Of course, the header would also contain the various function declarations.

    Quote Originally Posted by $l4xklynx
    The library and the header they could be of different file how are they able to communicate to each other? through the linker?
    What do you mean by "communicate"?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by laserlight View Post
    What do you mean by "communicate"?
    As to my understanding, The header file is a different file: graphics.h and a library I presume is a different file as well: graphics.lib... if the pointer to a structure is in the graphics.lib graphic library how is the graphics.h header use the pointer to a structure from graphics.lib?


    If i'm wrong with my understanding about the statement above, please correct me.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by $l4xklynx
    if the pointer to a structure is in the graphics.lib graphic library how is the graphics.h header use the pointer to a structure from graphics.lib?
    The pointer would likely be defined by the client code, which would then pass it to the various functions of the library.

    Coming back to C++ specifically, the pointer to the implementation class would be a member of the class that defines the interface, and the client code would then create objects of this class.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by laserlight View Post
    The pointer would likely be defined by the client code, which would then pass it to the various functions of the library.

    Coming back to C++ specifically, the pointer to the implementation class would be a member of the class that defines the interface, and the client code would then create objects of this class.
    And those objects that were created in the client code will send a message to the class and perform whatever behavior the object requested?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by $l4xklynx
    And those objects that were created in the client code will send a message to the class and perform whatever behavior the object requested?
    Yes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 05:32 AM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. Replies: 4
    Last Post: 04-01-2003, 12:49 AM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM