CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    What design pattern should I go for if I want to "sort of" convert the interface?

    Now I just got 2 projects to combine into one.
    There are 2 similar classes that behave more or less the same.
    One is called Unit in the pathfinding module and one is called the Object class in the main game module
    Now I just need to change the interface so I just need one of them to swing into actions.
    Should I use the adapter pattern to do so?
    I don't know because I am not actually *converting* the interface, just, so to speak, combine
    the 2 classes together without changing the source code itself?
    One thing to consider is that they may not use the same data structures.
    Grids Opposed to Navigation Meshes
    Thanks
    Jack
    Last edited by lucky6969b; May 24th, 2015 at 07:52 AM.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: What design pattern should I go for if I want to "sort of" convert the interface?

    it depends what you want to achieve.

    if they both have a same origin or abstractable similarity: consider making a base class and deriving both from that.
    if they both have different members that have a same origin or abstractable similarity: consider making a base class for that member.
    if they have some similar looking functions: consider templatized algorithms
    ... There could be dozens of other options but it's impossible to say without knowing more of what you're trying to do.


    adapter pattern has it's uses too, but that's more for cases where you can't or for other reasons don't want to change the interfaces, but do need a similarly behaving interface for different classes in another place in your code. If you're writing new software, it's a thing to avoid and to redesign your classes better. It may be a good way to get "old" software to interface to new design concepts without needing a total redesign/rewrite of lots of old code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured