In Java, I am used to writing an abstract class that does some setup work and then delegates to the concrete class like this:
public abstract class Base {
public void process() {
// do some setup
//...
// then call the concrete class
doRealProcessing();
}
protected abstract void doRealProcessing();
}
public class Child extends Base {
@Override
protected void doRealProcessing() {
// do the real processing
}
}
I am having a hard time doing this in Ruby because I don’t have abstract classes or methods. I also read that "you aren’t supposed to need abstract classes or methods in Ruby and that I should stop trying to write Java in Ruby".
I would love to know what is the right way to implement the equivalence in Ruby?
Welcome to dynamically typed languages! You were probably nervous about just defining some function that wasn’t declared anywhere. Don’t be worried. It is very easy:
EDIT: Here’s another option for you which avoids the need to have two different method names: