tags:

views:

83

answers:

1

Hello SO-Followers,

cowboy coder needs some help from SO-veterans:

I have a given application that uses a bibliography which is read from a file (in reality, it can be different files but let's assume a single file only).

I build a new application that should use the bibliography the same way than the application so I copied the according class(es).

After some days I got things running %-| ...

Problem was the following:

In the Bibliography class there is code to read, write and keep the bibliography. My work would have been much easier when there would have been one class to read the bibliography and a container class that keeps all values. I don't want to write or edit the bibliography, just read it in and keep the values.

So am I right in my idea that it would be best to segment the bibliography class into a BibliographyReader, BibliographyWriter and a Bibliography(Container) class?

P.S.: Could someone please create a tag "cowboy coder", "cowboy coding" or something similar? I really miss this tag ;)

+3  A: 

I like the approach of separating "container" classes from reader/writer/getter and so on, preferably defined by an interface. Search for "strategy pattern" and you will find more information about it.

A simple approach would be to have the Bibliography class accept an IBibliographyReader in its constructor, and then have a class implement that interface. When creating a Bibliography class you pass an instance of the concrete reader implementation to it.

Fredrik Mörk
I like the idea of IBibliographyReader: I could implement a class to read from textfile, one to read from a xmlfile and so forth.
Inno
I do this with any semi-complex data storage. It makes it a lot easier to unit test everything.
Jamie Penney

related questions