Skip to main content
added 557 characters in body
Source Link
Caleb
  • 39.3k
  • 8
  • 96
  • 153

GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

invalidateRect(this->framem_frame);

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

invalidateFrame();

But why add a special method just for this when you can use the more general invalidateRect()? Or, if you did choose to provide invalidateFrame(), you'd very probably implement it in terms of the more general invalidateRect():

View::invalidateFrame(void)
{
    invalidateRect(m_frame)
}

Why pass variable as method parameter, if you already has access to it?

You should pass instance variables as parameters to your own method if the method doesn't operate specifically on that instance variable. In the example above, the view's frame is just another rectangle as far as the invalidateRect() method is concerned.

GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

invalidateRect(this->frame);

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

invalidateFrame();

But why add a special method just for this when you can use the more general invalidateRect()?

GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

invalidateRect(m_frame);

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

invalidateFrame();

But why add a special method just for this when you can use the more general invalidateRect()? Or, if you did choose to provide invalidateFrame(), you'd very probably implement it in terms of the more general invalidateRect():

View::invalidateFrame(void)
{
    invalidateRect(m_frame)
}

Why pass variable as method parameter, if you already has access to it?

You should pass instance variables as parameters to your own method if the method doesn't operate specifically on that instance variable. In the example above, the view's frame is just another rectangle as far as the invalidateRect() method is concerned.

Source Link
Caleb
  • 39.3k
  • 8
  • 96
  • 153

GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

invalidateRect(this->frame);

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

invalidateFrame();

But why add a special method just for this when you can use the more general invalidateRect()?