Back to Programming Languages forum
Hello All and thank you for your help!
Please bare with me. I am brand new to programming. I was admiring code written by user Signum_X but since he hasn't logged in for a while, I didn't ask him this question.
If anyone can teach me, or point me to resoources to learn from, I would greatly appreciate it.
In the code below why would you want to inherit from a bass class Problem? Is this to make it easier to load the using statements and such? That is the only thing I can think would be accomplished.
Also, what does all of the code after Problem_001() accomplish? Does he have his project setup to somehow load the problem straight from the site, or is this his internal structure? I don't understand it and I dont understand why one would do it LOL
class Problem_001 : Problem
{
public Problem_001() : base(1, "Sum \"A+B\"", "http://www.codeabbey.com/index/task_view/sum-of-two") { }
internal override void Solve(string[][] input, System.Text.StringBuilder output)
{
//Redacted as to not give solution to problem
}
}
MANY THANKS for your time and help!
Hi Edward!
Really, curious piece of code :)
Problem
- I think that author had there, in the base class, some code which performs data
loading (for input), calling of Solve
(implemented in the child class) and then providing output to console;As about "why do it", well, there could be various situations. Firstly, of course, providing general code for input and output in the base class - this won't help much, as these are just a few lines probably. This would be what is often called "overengineering". Though it is less or more ok if done for educational purposes. Many students when learning languages like C# or Java got idea that everything should be written in "Object-Oriented" way...
On the other hand, the author may wanted to use unit-tests for example, so that he can write several "testcases" and
run them against Solve
function automatically, without manually providing input and reading output himself each time.
If so, then this Problem
base class (which we don't see) could be a part of infrastructure for such tests. Of course
this doesn't make much sense for smallest problems, like this - but for more complicated this could be convenient.
And providing practice on this approach (unit-testing), widely used in industry :)
Surely I have no ready answer - but hopefully my guesses may shed some light on your puzzle!