Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad practice to pass "this" as parameter inside its own constructor?

Tags:

c#

.net

I have this BdlTabItem which receives a parameter of type DockableUserControl and would like to know if is it a bad practice to create a circular reference between the two by using uc.TabItem = this and new BdlDockableWindow(this) before the constructor finishes.

I know this behavior can be considered really bad with unmanaged native code (C++). So, even though I didn't have any warnings or errors, I ask here if I should do this or not.

public BdlTabItem(BdlTabControl parent, DockableUserControl uc, string title)
    {
        TabControlParent = parent;
        UserControl = uc;
        WindowParent = new BdlDockableWindow(this);

        this.Content = UserControl;

        UserControl.TabItem = this;
    }
like image 504
Alexandre Severino Avatar asked Apr 23 '15 17:04

Alexandre Severino


1 Answers

This is acceptable, but raises questions. Why is the tab item instantiating a new WindowParent but the parent tab control doesn't have a reference to it? Or why isn't the window parent a property on the user control being passed in? Seems like the behavior should be elsewhere.

like image 113
moarboilerplate Avatar answered Nov 01 '22 06:11

moarboilerplate