From the course: Advanced Python: Build Hands-On Projects with Design Patterns (2023)

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Access control

Solution: Access control

- [Instructor] Were you able to figure out the answer? In this challenge, I created an InterceptingValidator class for you. The self._validator attribute is where I store a reference to my validator that will validate an embedded input, t, I stored in the self._input attribute. I also have a method called set_validator to set the ._validator attribute to the validator I want, right here. The last method in the InterceptingValidator class is validate. This method invokes the validate method of my validator and returns the result of the validation. The result is either True or False. Let's now examine the NumberValidator class. I use this class to check if my input is a number or not. The validation process occurs in the validate method. I set the int_or_not variable to None initially. The goal is to set it to True if the input can be turned into an integer. Otherwise, the validate method should return False. I…

Contents