OO Design whose responsibility input/output? - oop

I have a datasource (in this case a data file (HDF5), but might as well be something else like a DB). I want to load the data and output plots and pdf's (and maybe more in the future). Now how would I implement all these dependencies?
I feel a "data" class should only focus on containing and working with the data and not the loading of the data or the creation of output (pdf, image or other). However, the class does know what the data looks like and how it can be best plotted for example.
How would one build such a system in OOP?

Related

What is a proper way to separate data structure logic from its graphical representation?

It's more of a software design question, than strictly programming, so I'll paste UML diagrams instead of code for everyone's convenience.
Language is Java, so variables are implied references.
I'm writing an app, that helps edit a very simple data structure, that looks like this:
On my first trial run I've included all the drawing-related and optimization code into the data structure, that is, every Node knew how to draw itself and kept a reference to one of shared cached bitmaps. UML:
It was easy to add (fetch a corresponding bitmap and you're done) and remove (paint background color over previously mentioned bitmap). Performance-wise it was nice, but code-wise it was messy.
So on the next iteration I decided to split things, but I may have went to far and things got messy yet again:
Here data structure and its logic is completely separated, which is nice. I can easily load it from file or manipulate in some way before it needs to be drawn, but when it comes to drawing things get uncomfortable.
The classic way would be to change data then call invalidate() on drawing wrapper,but that's inefficient for many small changes. So to, say, delete 1 Tile Id have to either have Drawn representation be independent of Data and call deketeTile() for both separately, or funnel all commands to Data through Drawing class. Things get even messier when I try to add different drawing methods via Strategy pattern or somehow else. The horror:
What wis a clean efficient way to organize interactions with Model and View?
First, definitely decouple the app logic from UI. Make some model for your schematic. That will solve your trouble to unit test the app model, as you already said. Then I would try the Observer pattern. But given that a schematic can have lots and lots of graphical components (your Tiles), I would change the usual setup for notifying every observer when something changes in the model, to notifying only the corresponding GraphicalComponent (Tile), when a Component gets changed in the Model. Your UI asks Model to do things, and gets called back in some parts to update. This will be automatic, no duplicated calls, just the initial observer registry on GraphicalComponent creation.

Create owl file from csv file

Currently I am using Protege application to add classes, sub classes for the added classes and label for each subclass/class. I have many classes and I am really fed up adding many of these manually. I have got all of these classes, sub-classes and labels in a csv file. Each row contains these three things- class,sub-class and label separated by comma.
I would like to create OWL file with all these classes. Is there any way I could automate the process?
This use case seems pretty close to what a tool named Populous does. See its description here
Populous presents users with a table based form in which columns are constrained to take values from particular ontologies. Populated tables are mapped to patterns that can then be used to automatically generate the ontology's content. These forms can be exported as spreadsheets, providing an interface that is much more familiar to many biologists.
The table/spreadsheet format is equivalent to CSV, so easy to convert. The project is Open Source, so easy to reuse the code to achieve your target.
See http://www.populous.org.uk/ for more details.

Building an Interface for User Generated Graphs

I've researched this issue and have not found anything to meet my needs. I am worried that perhaps I'm using the wrong terms.
I would like to build a website interface that allows users to select different variables and then have those variables dynamical or automatically graphed or charted. I need it to be able to handle 100+ variables (there could be limits to how many were charted at one time) and display the data on a bar graph, pie chart, or line graph based on the users preference.
What would I need to make this happen?
Sounds like you need to use either Flash and ActionScript or JavaScript and HTML5.
I've been looking to do something like this too actually.
Need a facility for parsing the data, and then working out scales/ratios and to represent the data in a coherent way, with labels. Then you need to scale the shapes your using according to the scale that the data is covering, and for the sizes to naturally be proportional.

A little help with MVC

I'm working on a cocoa app for syncing data between two folders.
It have profiles (so you can have multiple setups)
It's possible to analyze data
It's possible to sync the data
Im a little confused. First of all i cant really see where to have a model? And how many controller would you suggest? 1 WindowController or AnalyzeController, SyncController etc.
Its quite a while since i have worked with MVC. I've read some articles but i'm missing concrete examples on how to divide it.
Best regards.
The data model handles the data and the abstract relationships between different pieces of the data. The controllers handle the concrete operations of a computer or human interface.
The key division is that the data model doesn't know where the data comes from and doesn't care. For example, it could model a folder and its contents but the actual information in the model could come from a real folder on a disk or it could come from completely made up plist file or it could come from a simulated UI of a folder. The data model doesn't care because it has no direct connection with concrete reality. It just holds an abstract description of the data.
The controllers by contrast are tied to a specific concrete interface. For example, if you have two folders, you would have specific controllers for each folder. Each controller would have concrete knowledge of the real world pathway to the folder as well as the mechanism for reading and writing to the folders. So, if one folder is on the local hard drive and another is remote, each controller would understand the difference. If you have a UI, then the UI would have its own controller.
The controllers job is to translate from the concrete reality to the abstract model. In this case, the controller would handle connecting to a remote server, scanning the folder and then converting that information to an abstract form it would hand off to the data model. However, the controller doesn't save an data and doesn't understand how the pieces of data relate to each other.
In the case of a syncing app, it would be the job of the data model to understand what files where in which folder and what files needed to be copied or updated and to where. It would then tell each controller which files to manipulate. However, the controller wouldn't know why each file was being manipulated.
The design goal is to create a data model that would model the folders and files regardless of where they reside, how they are concretely manipulated or even whether they actually exist at all. That way, you can easily add or remove interfaces just by adding or removing a controller. The controllers themselves are simple because they hold no data and no data manipulation logic.

hidden information in wxGrid

I've got a wxGrid that I populate dynamically. I'd like to store some information with each row that shouldn't be displayed to the user. What is the best way to associate data with a row? Should I just create a hidden column or is there a better way?
Creating a hidden column is the fastest, but indeed a very ugly method. If you can justify the effort, then you should better create your own grid table base class. Your own wxGridTableBase-derived class can hold any information you need it to, without the need to show it in the grid. Unfortunately the documentation for that class is sparse or nearly non-existent.
For an example see the grid demo in the wxWidgets samples directory, specifically the BugsGridTable class. What you will notice is that you do not necessarily store the strings that the grid will display, but you can format your data in the GetValue() method. This can be a lot better, both in terms of memory consumption, and because you can change the format of displayed data on-the-fly.
The switch to a custom grid table base class has had a big impact on speed, memory consumption and functionality for the result set data grid of FlameRobin, an administration tool for the Firebird relational database. You can always check out its source code for how we use wxGrid.
Store the value in the row label using SetRowLabelValue and hide the row labels.