SOLID principle problem
-
I'm stuck with applying the SOLID principle in my code. Problems: 1) I don't want to violate SRP, so I don't know if the protected members of AbstractScreen are violating this 2) My screen interface should not have this many responsibilities, I probably need to remove them 3) I decided to make a DocumentLoader class to take care of providing my screens with the input and output documents they need in order to display something on the screen. What is displayed depends on the input and output file I give it. Thus I made the DocumentLoaderInterface, with loadDocuments(List). This is my real problem: where am I going to put the implementation of loadDocuments() if it varies per screen? I can't posssibly go put this code in a screen, because that will give the screen too many responsibilities. If I implement it in the DocumentLoader class, then only one implementation will be available, unless I make several DocumentLoader objects. Where do I instantiate them? If I call documentLoader.loadDocuments(); then where is the implementation going to be? How do I implement this?.. I'm really stuck. Please find below my code structure: package screens: Screen AbstractScreen
protected Document inputDocument, outputDocument;
protected SAXBuilder parser;
protected ComponentService componentService;
protected DocumentLoader documentLoader;ScreenInterface:
public Document getScherm();
public void addComponents();
public Object getC(String key);
public void loadDocuments();package ui:
TestUi
package utils:
ComponentService
UtilityFactorypackage xmlio:
DocumentLoader
DocumentLoaderInterface
XmlIo
XmlIoInterface//Application Goal: Have a GUI draw a XAML screen depending on the input XML document. Different documents will produce different charts.
-
I'm stuck with applying the SOLID principle in my code. Problems: 1) I don't want to violate SRP, so I don't know if the protected members of AbstractScreen are violating this 2) My screen interface should not have this many responsibilities, I probably need to remove them 3) I decided to make a DocumentLoader class to take care of providing my screens with the input and output documents they need in order to display something on the screen. What is displayed depends on the input and output file I give it. Thus I made the DocumentLoaderInterface, with loadDocuments(List). This is my real problem: where am I going to put the implementation of loadDocuments() if it varies per screen? I can't posssibly go put this code in a screen, because that will give the screen too many responsibilities. If I implement it in the DocumentLoader class, then only one implementation will be available, unless I make several DocumentLoader objects. Where do I instantiate them? If I call documentLoader.loadDocuments(); then where is the implementation going to be? How do I implement this?.. I'm really stuck. Please find below my code structure: package screens: Screen AbstractScreen
protected Document inputDocument, outputDocument;
protected SAXBuilder parser;
protected ComponentService componentService;
protected DocumentLoader documentLoader;ScreenInterface:
public Document getScherm();
public void addComponents();
public Object getC(String key);
public void loadDocuments();package ui:
TestUi
package utils:
ComponentService
UtilityFactorypackage xmlio:
DocumentLoader
DocumentLoaderInterface
XmlIo
XmlIoInterface//Application Goal: Have a GUI draw a XAML screen depending on the input XML document. Different documents will produce different charts.
Working from the bottom up, you should implement all the data logic below the UI layer. Have a class that loads the document, it will know how to interpret the document and get the definitions out. Then have asingle UI class read the data to define itself. This allows different UI's to use the same data class and can make supporting multiple platforms - desktop, tablet, web - much easier as you only need to implement the UI once per UX variant.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett