Jump to content
  • Advertisement

El OsO AntiGuo

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

112 Neutral

About El OsO AntiGuo

  • Rank
    Newbie
  1. El OsO AntiGuo

    Help to abstract dependency?

    Sorry but i don't understand what you mean.  The UI is still calling new on the concrete type.  Could u provide a more "codeish" example that might help me understand easier
  2. I have a requirement where the the user needs to configure how they would like to get alerted when an error happens.  The options they have are the following:   1.) Create an event in the event log   2.) Send an email to an email specified from the user interface   The classes i am using currently use the following interface       interface INotificationSender     {        virtual void SendMessage(string message);     }   my interface is going to be implemented by the following 2 concrete classes       class EmailerNotificationSender: public INotificationSender     {        string m_EmailAddress;             public EmailerNotificationSender(string emailAddress)        {            m_EmailAddress = emailAddress;        }        public virtual void SendMessage(string Message)        {           // Send Message to email specified in member variable        }     }                class EventLogNotificationSender: public INotificationSender     {        public virtual void SendMessage(string Message)        {           // Log message in event log using        }            }       My current interface code looks like the following           public class MyUserinterfaceWindow     {         private INotificationSender m_NotificationSender; // concrete type depends on user interface selection!              public void Button_Click(...)         {            if (emailSelected)            {                m_NotificationSender = new EmailerNotificationSender(textbox.email)                return;            }             m_NotificationSender = new EventLogNotificationSender();         }              public void SendAlert()         {             m_NotificationSender.SendMessaged("SOMETHING BAD HAPPENED");         }     }     **Summary/Question:** How do i remove the presence of concrete types being instantiated( for example EventLogNotificationSender and EmailerNotificationSender )   **NOTE:** EventLogNotificationSender requires no parameters in it's concrete constructor while EmailNotificationSender's concrete constructor takes a string parameter!
  3. El OsO AntiGuo

    Help with Dependency Injection Scenario

    This approach seems actually like a good idea since i am wanting to hide the implementation detail of a HWND from my calling code.  How would u go about using this struct?  like where would u initialize it and where would u pass it in?
  4. El OsO AntiGuo

    Help with Dependency Injection Scenario

    Hehe you understand my question right on!     1.) Adding an Initialize function - I could but does it really make sense for an interface to have a method called initialize? to me it doesn't really make sense from an interface perspective.   2.) Passing HWND into a member function as a parameter - I was wanting to avoid passing a HWND directly to the interface.  Why might you ask?  What if i wanted ot use this IRenderer interface with some other platform( linux..etc ).  Linux doesn't use HWND's and therefore i would be strictly creating this interface for windows programs to use.   Any other advice is greatly appreciated.  
  5. El OsO AntiGuo

    Help with Dependency Injection Scenario

      My reasoning is that the renderer should be able to draw to many targets and not just "windows".  Therefore the IRenderer should represent the operation of performing drawing operations, regardless of destination.  CDesktopWindow "is-implemented-in-terms-of" an IRenderer to perform the actual drawing.   This is my Opinion :)  Let me know if i seem wrong for thinking this
  6. I currently have 3 classes which are listed below and a description of them is followed: CDesktopWindow - Contains the window creation code, message loops, window handle, etc... CRenderer - Contains all directx related code and HWND to initialize directx so it knows where it needs to draw to. IRenderer - Interface that contains 1 pure virtual function call draw() class CDesktopWindow {   HWND m_hwnd;   IRenderer* m_renderer    CDesktopWindow(IRenderer* renderer)    {      m_renderer = renderer;    }   void Draw()   {      // Drawing logic here m_renderer->Draw();   } }; My renderer interface looks like so: struct IRenderer {      pure virtual void Draw() =0; }; Summary:   The issue i am running into is that my CDesktopWindow class "has-a" IRenderer interface that is in charge of performing all the drawing for my application. The implementation i have for IRenderer ( which is CRenderer ) takes a HWND for a constructor.  It needs this to initialize direct3d properly.  The problem is, the window HWND get's created later on.  I hope this makes sense.  Does anyone have any recommendations on how to solve this circular depedency.   Essentially, all i want to do is inject a IRenderer interface to be used within CDesktopWindow, except the concrete implementation of IRenderer that i have MUST have a handle to the window, which isn't created until CDesktopWindow.Create() is called.   // Example of object creation/ dependency injection { IRenderer* renderer = new CRenderer( {I need window handle here } );    // How do i get the below created window handle in here? CDesktopWindow* desktopWindow = new CDesktopWindow( renderer ); desktopWindow.CreateWindow();    // Create HWND for application window desktppWindow.Run();   // run message loop }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!