Lost access to same property trying to use best practice / design pattern

Luk

New Member
I had:
  • in a class implementing Validator:
    • an $errormessages property
    • an isCorrect() method
In the isCorrect method, I had:\[code\]switch ($type): case 'email': isEmailCorrect(); case 'password': isPasswordCorrect(); case 'x': isXCorrect();\[/code\]isEmailCorrect(), isPasswordCorrect() and isXCorrect() had access to the same property with all error messagesNow, I have:
  • in Validator:
    • an $errormessages property
  • in an EmailValidator class extending Validator:
    • an isCorrect() method
  • in a PasswordValidator class extending Validator:
    • an isCorrect() method
  • in a XValidator class extending Validator:
    • an isCorrect() method
Now, in a file calling the isCorrect() methods, I have:\[code\]$EmailValidator = new EmailValidator();$PasswordValidator = new PasswordValidator();$XValidator = new XValidator();\[/code\]\[code\]$EmailValidator->isCorrect()\[/code\], \[code\]$PasswordValidator->isCorrect()\[/code\] and \[code\]$XValidator->isCorrect()\[/code\] don't have access to the same property with all error messages$errormessages are in different instances of different classes. They should be one, but are three.What now?
 
Back
Top