Class Kata "Ordered Jobs"

Develop a class that creates a plan for processing interdependent jobs [1].

Each job is represented by a letter, e.g. "c" or "x".

It is possible that a job "u" must be processed before a job "a". Then "a" is dependent on "u". Of course, each job can be dependent on any number of others and these in turn can be dependent on others...

After a series of jobs with their dependencies have been registered, the class should bring them into a processing sequence in which dependencies come after those on which they depend.

The interface for this looks like this:

interface IOrderedJobs {
  void Register(char dependentJob, char independentJob);
  void Register(char job);

  string Sort();

If registered as follows...

Register('b', 'a');
Register('c', 'b');

...then delivers Sort() this result:


Jobs that occur in several registrations only appear once in the sorting.

Independent jobs can be sorted in any order as long as they are processed before those that depend on them.

Direct or indirect circular dependencies should be reported via an exception - at the latest during sorting.


Implement an alternative function string Sort(string registrations)which accepts registrations in the form of a multi-line character string of the following form [1]:

c =>
b => a
c => b


[1] The Ordered Jobs Kata,