iceoryx icon indicating copy to clipboard operation
iceoryx copied to clipboard

Remove creation design pattern class with in place implementation

Open elfenpiff opened this issue 2 years ago • 0 comments

Brief feature description

Inheriting from the creation design pattern class has certain drawbacks which can be very error prone.

  1. In move and copy operations one has to delegate the call to the base class first
  2. m_isInitialized, m_errorValue are sometimes overlooked or not set correctly
  3. the creation class has to be a friend class of the resource which is using it

A better implementation alternative would be to create a static method in such classes called create and create the system resource directly in there and provide the handle to that successfully created resource to the constructor of the class. The constructor does not create the system resource it just acquires a existing one and handles its lifetime.

Another approach is to introduce a builder pattern when the class constructors requires more then zero arguments to improve the readability.

Classes where Creation pattern must be replaced with static create method

  • [x] SharedMemoryObject
  • [x] MemoryMap
  • [x] SharedMemory
  • [ ] UnixDomainSocket (high prio)
  • [ ] MessageQueue (medium prio)
  • [ ] NamedPipe (medium prio)
  • [x] FileLock
  • [x] Semaphore (will be solved in #751)
  • [x] Mutex (high prio)
    • [x] Implement builder pattern
    • [ ] Integrate new API into iceoryx and remove old constructor, all @todo iox-#1036 should be gone
  • [ ] move creation.hpp to iceoryx_dust (high prio)

elfenpiff avatar Jan 22 '22 06:01 elfenpiff