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 - Python Tutorial
From the course: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.