if i have this constructor (newFromAandB) in a parent class
public class Parent
{
private str a,b;
public static Parent newFromAndB(str _a, str _b)
{
Parent parent = new Parent();
parent.parmA(_a);
parent.parmB(_b);
return parent ;
}
public str parmA(str _a = a)
{
a = _a;
return a;
}
public str parmB(str _b = b)
{
b = _b;
return b;
}
private static Parent construct()
{
return new Parent();
}
protected void new()
{
}
public void validate()
{
if( a == '')
{
throw error ("a should be filled");
}
}
}
public class Child extends Parent
{
public void validate()
{
//Skip parent validation
}
}
if I do this, then child will be empty
Child child = Parent::construct(a, b) as Child;
and i can't do this, because the new in the parent is protected and the child will still be empty anyway
Child child = new Child();
child = Parent::construct(a, b);
Is the only solution to define a constructor in the child class with exactly the same code as in the parent for it to work? can't I utilize the parent class method?
public class Child extends Parent
{
public static Child newFromAndB(str _a, str _b)
{
Child child = new Child();
child.parmA(_a);
child.parmB(_b);
return child;
}
public void validate()
{
//Skip parent validation
}
}
what would u do in this case in the construct method?