Compilation dependency and the pimpl idiom

This is a discussion on Compilation dependency and the pimpl idiom within the C++ Programming forums, part of the General Programming Boards category; It's that I like value semantics. Ah. Well, appearance and familiarity is a factor in good design. If you want ...

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    3,797
    It's that I like value semantics.
    Ah. Well, appearance and familiarity is a factor in good design.

    If you want to hide implementation details, use interfaces, unless you already intend to use the Bridge pattern.
    No. I had "polymorphisms" in mind anyway and my post was written within that context.

    Another reason would be copy-on-write semantics.
    O_o

    No. You don't need to introduce "Pimpl" (pointer-to-implementation or "Handle/Body" if you prefer) to satisfy "Copy-on-Write".

    If the implementation details don't need to be hidden (You might have, for example, a simple string class with value semantics having no need for system specific details so no need to hide implementation details at all.) you only need reference counting and the ability to copy the "value".

    If you have a value class referencing unknown state you've already introduced the need for the "Pimpl" or other facility that may hide implementation details (The value class from the point of view of the client already does not know the implementation details.) so you can use that same mechanic to get "Copy-On-Write".

    Soma
    Last edited by phantomotap; 07-08-2012 at 03:02 PM.

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Quote Originally Posted by phantomotap View Post
    No. You don't need to introduce "Pimpl" (pointer-to-implementation or "Handle/Body" if you prefer) to satisfy "Copy-on-Write".

    If the implementation details don't need to be hidden (You might have, for example, a simple string class with value semantics having no need for system specific details so no need to hide implementation details at all.) you only need reference counting and the ability to copy the "value".
    You need to separate state from the primary object if you want multiple objects to share one state until a write occurs. Therefore, you will have a handle/body design anyway, and you might as well hide the body from clients. You don't have to, of course.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    3,797
    O_o

    Well, yeah, if your definition of "Handle/Body" is any class that may share state via pointer then you would be right.

    That isn't the definition though; you are just misusing the jargon.

    The "Handle/Body" idiom was born to "hide the body from clients".

    A pointer to state is just that: a pointer to state.

    Soma

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Fair enough.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding forward declarations of classes, pimpl
    By Boxknife in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2010, 01:29 AM
  2. Identifying a C++ idiom
    By kovacsbv in forum C++ Programming
    Replies: 2
    Last Post: 08-10-2009, 02:50 PM
  3. pimpl confuses me
    By manav in forum C++ Programming
    Replies: 8
    Last Post: 03-30-2008, 10:31 PM
  4. Inheritance in Pimpl idiom
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2008, 09:32 PM
  5. Pimpl Idiom client/serve compile/link
    By George2 in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2008, 06:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21