Connecting data to a GUI - OOP

Posted by tau on Stack Overflow See other posts from Stack Overflow or by tau
Published on 2012-10-25T22:45:49Z Indexed on 2012/10/25 23:00 UTC
Read the original article Hit count: 170

Filed under:
|
|
|

I have an application with several graphs and tables on it.

I worked fast and just made classes like Graph and Table that each contained a request object (pseudo-code):

class Graph {
  private request;

  public function setDateRange(dateRange) {
    request.setDateRange(dateRange);
  }
  public function refresh() {
    request.getData(function() {
      //refresh the display
    });
  }
}

Upon a GUI event (say, someone changes the date range dropdown), I'd just call the setters on the Graph instance and then refresh it. Well, when I added other GUI elements like tables and whatnot, they all basically had similar methods (setDateRange and other things common to the request).

What are some more elegant OOP ways of doing this?

The application is very simple and I don't want to over-architect it, but I also don't want to have a bunch of classes with basically the same methods that are just routing to a request object. I also don't want to set up each GUI class as inheriting from the request class, but I'm open to any ideas really.

© Stack Overflow or respective owner

Related posts about oop

Related posts about design-patterns