课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Creational patterns - Python教程
课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Creational patterns
- [Instructor] There are three different types of design patterns: creational, structural, and behavioral patterns. Creational design patterns are for building objects systematically. The main benefit lies in their flexibility, especially in the area of modifiability and scalability. Here is an example of using creational patterns to make code changes more elegant and effective. Let's say that you're developing software for a pet shop. If you're short-sighted, you may create individual classes for each pet the shop offers as you go. This approach is not scalable. A better option is to have a general class called Pet that contains all the common properties across the pets being handled now and to be added in the future. These common properties include: pet type, such as dog or cat, their name, age, et cetera. When there is a new pet type to be introduced next time, all you have to do is to write a new child class that…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。