soldiershin
soldiershin

Reputation: 1620

Query regarding design(interface and classes)

I am basically writing a code which reads a text file, stores it in a string, does some operations with the string and displays it on a dialog, then writes the file if some changes are made. Now i have made separate interfaces for FileRead, FileWrite, StringHandling, LineHandling, Database and i have a controller class which implements these interfaces and i just call the instance of controller class in gui.. I wanted to ask that if the design is ok or do I need a separate class implementation for each interface.

Upvotes: 0

Views: 40

Answers (1)

André Stannek
André Stannek

Reputation: 7863

I think for such a small project it is acceptable but generally I would consider it bad design for two reasons:

  • As you suspected one class implementing all these interface might be a bad idea. Depending on what the interfaces do you are getting a god class which does to many things that don't have anything to do with each other. Under the aspect of enclosure you basically want one class to do one thing or better said have only one remit.
  • The fact that your controler class implements the interfaces is also conserning me. A controler class (in sense of UI programming) shouldn't do business logic. It should offer methods in a way that it is needed by the UI. Those methods then should call the the classes that do the acual business logic. They at most might do some "translations" between UI and backend like collecting the needed data from the UI and converting it into whatever is needed by the business logic methods. Also the other way around: Calling several business logic methods and agregate their results.

As I said for such a small tool it might be considerd OK but it's never a bad thing to have your architecture straight ;-)

UPDATE

If you follow these two points you still only need one controller class. It can refer to the different classes that do your logic.

Upvotes: 1

Related Questions