Darren Young
Darren Young

Reputation: 11090

Class Architecture Question

Just after some opinions on this fairly simple issue.

Say, I have a DocumentParser class, that extracts lots of data from an excel spreadsheet. The data that is captured is modelled with another object, lets say 'DataObject'. The document parser builds a collection of these objects, ready for transfer into a large range of datasets, for further tasks to be performed.

My question is, would you implement the dataset population in the same class as the Document Parser, or adhering to the Single Responsibility Principle, would you make that a new class? If it is a seperate class, how would you expose the collection of data objects to that class, would you simply pass through as a parameter?

Thanks.

Upvotes: 0

Views: 37

Answers (1)

Liv
Liv

Reputation: 6124

your DocumentParser class has only one responsibility: and that is to parse the data and return a data structure from it. Use a different class to process this dataset -- similar if you will to the whole parsing XML (returns a Document) and writing this document back to XML! I would suggest wrapping up your collection of DataObject into another class which allows iteration through it (again, look at the way XML Document parsing works) and then pass that encapsulated data rather than just a simple collection of DataObject.

Upvotes: 1

Related Questions