Is there anything wrong with wrapping a top-down class in a static method

I know how to program, but i want to become a better programmer. I have certain classes that are more IO oriented. One takes in a url with a macro, some page numbers, and an downloader interface, an some xpath to combine many htmls into one managable xml.

The problem comes in my mind is, do i let the end user access the methods that do the work, or do i make the class have one single "run" method? Or do i leave the class as is, with no run method, and add a method to a utility class that simply constructs the object and returns its ultimate value.

making a class with a single public method feels wrong, but on the other hand, making a bunch of public methods that could be relied on, and therefore kill my ability to re-factor also feels wrong.

Answers


Your problem here seems to be the single responsibility, your method seems to be doing (too) many different things and thus would require many public methods to be testable. This is a common pointer that a class is "wrongly" built when writing unit-tests.

What I would recommend here is to split your class into multiple ones, each containing part of the logic and one responsibility only. In each of those classes, the main method is public and does the intended job while being testable. The original class now has the job to use the output of those other objects without "knowing" how they are doing it.


Need Your Help

Visual Studio Setup Project Installer Prerequisite for SQL Server CE

visual-studio-2008 windows-installer

I have a Setup Project in my solution in Visual Studio 2008 SP1. The application installs fine but it is not loading my prerequisite of SQL Server CE.

Component install error: JInstaller: :Install: File does not exist

php joomla joomla3.0

I have created a component simply by following this video. I have created my component named admin.zip. I am getting this following warning while installing in joomla 3.0.