Intermediate Object-Oriented Programming in Python
Jake Roach
Data Engineer
class Student:
# सभी स्थितियों के लिए समान व्यवहार वाली कंडीशनल लॉजिक
def explore_topic(self, resource_type, topic):
if resource_type == "Textbook":
print(f"Referencing {topic} using a textbook")
self.reference_textbook(topic)
elif resource_type == "Blog":
print(f"Make sure to validate information provided in blogs!")
self.reference_blog(topic)
elif resource_type == "Video":
self.reference_video(topic)
डिज़ाइन पैटर्न जिसमें फ़ैक्टरी मेथड्स से ऐसे ऑब्जेक्ट बनते हैं जो किसी दूसरे मेथड में काम आते हैं
_ का उपयोग$$
पहले, products और concrete products देखते हैं!
...
def _get_resource(self, resource_type):
if resource_type == "Textbook":
# Textbook, Blog और Video सभी
# resources हैं
return Textbook()
elif resource_type == "Blog":
return Blog()
elif resource_type == "Video":
return Video()
class Resource(ABC):
@abstractmethod
def reference(self, topic):
pass
class Textbook(Resource):
def __init__(self):
self.index = {"Object-oriented Programming": ["Inheritance", ...]}
def reference(self, topic):
print(f"Referencing {topic} using a textbook")
return self.index.get(topic)
# Blog, Video के लिए भी कुछ ऐसा ही
class Student:
def explore_topic(self, resource_type, topic):
if resource_type == "Textbook":
texbook = Textbook() # Resource इम्प्लीमेंट करने वाली class का instance बनाना
texbook.reference(topic) # reference() मेथड कॉल करें
elif resource_type == "Blog":
blog = Blog()
blog.reference(topic)
elif resource_type == "Video":
video = Video()
video.reference(topic)
class Student:
# Resource लौटाने वाला फ़ैक्टरी मेथड
def _get_resource(self, resource_type):
if resource_type == "Textbook":
return Textbook()
elif resource_type == "Blog":
return Blog()
elif resource_type == "Video":
return Video()
def explore_topic(self, resource_type, topic):
resource = self._get_resource(resource_type) # resource लें
return resource.reference(topic)
# Student ऑब्जेक्ट बनाएँ, फिर इसे textbook रेफ़रेंस करने दें
lester = Student()
lester.explore_topic("Textbook", "Object-oriented Programming")
# दूसरे resource पर स्विच करना आसान
lester.explore_topic("Video", "Object-oriented Programming")
Referencing Object-oriented Programming using a textbook
["Inheritance", "Constructors", "Class-level methods"]
Video are helpful for visual or audatory learners
["Classes", "Methods", "Attributes", "self"]
Intermediate Object-Oriented Programming in Python