炒房是什么意思| 胰腺在什么位置| 三问表是什么意思| 为什么抽烟会恶心想吐| 是否是什么意思| 狗狗中毒了用什么办法可以解毒| 为什么老流鼻血| 内热吃什么药| 清明节在什么时候| 后知后觉什么意思| 左大腿外侧麻木是什么原因| 血压不稳定是什么原因| 循序渐进是什么意思| 手心烫是什么原因| 白什么| 舌苔白厚吃什么药见效快| 奔三是什么意思| 补刀什么意思| 心脏病有什么症状| 结节病变是什么意思| 牛油是什么油| 此地无银三百两什么意思| 嘉靖为什么不杀严嵩| 廿读什么| 两个水念什么| 有偿服务是什么意思| 限购是什么意思| 成双成对是什么生肖| 豆是什么结构| 谷什么意思| 命门是什么意思| 万事如意是什么生肖| 丑时是什么时辰| 什么是羊水栓塞| 嗓子有痰是什么原因| 家里养什么动物吃蟑螂| 以马内利是什么意思| 完美收官什么意思| 出淤泥而不染是什么花| 五光十色是什么生肖| 邦字五行属什么| 老打饱嗝是什么原因| dha每天什么时候吃最好| 呲牙是什么意思| 6.25什么星座| 挚友是什么意思| 脂溢性皮炎是什么引起的| 什么是半衰期| 拔罐是什么意思| 甘油三酯高有什么症状| 肺部斑片状高密度影是什么意思| 沉沦什么意思| 氯气是什么颜色| rbp是什么意思| 多吃核桃有什么好处和坏处| 女人背心正中间疼是什么原因| 自言自语是什么| 人参果总皂苷是什么| 最不干净的动物是什么生肖| 观音菩萨代表什么生肖| 尿液发臭是什么原因| 支气管舒张试验阳性是什么意思| 参见是什么意思| 哈伦裤配什么鞋子好看| 夜开花是什么菜| 仌是什么字| 臆想什么意思| 傍家儿是什么意思| 西夏是什么民族| 男生下体痒是什么原因| 补血吃什么| 腰的左侧疼是什么原因| 香芋是什么| 梦见自己生二胎是什么意思| 东方美人茶属于什么茶| 双子座爱吃什么| 睡觉中途总醒什么原因| 调经吃什么药效果最好| 大惊小怪是什么意思| 西米是用什么做的| 不见棺材不落泪是什么生肖| 二聚体测定是什么| 大便细是什么原因| 戈谢病是什么病| 四眼狗是什么品种| 肾结石什么不可以吃| 紫癜是一种什么病| 爱之深恨之切是什么意思| 北京有什么好吃的美食| 女生的隐私长什么样子| 偶尔是什么意思| 拜复乐是什么药| 送男教师什么礼物合适| 左侧上颌窦囊肿是什么意思| 喜怒无常是什么意思| 紫癜有什么症状| 1984年属鼠是什么命| 嘴碎什么意思| 病入膏肓是什么意思| 咽炎吃什么| 月抛什么意思| mu是什么单位| 晚上经常做梦是什么原因| 囊性结节是什么意思| 陆代表什么生肖| 脉压是什么意思| kawasaki是什么牌子| 吃什么补气| 康普茶是什么| 一什么铃铛| kumpoo是什么牌子| 大利月小利月什么意思| hoho是什么意思| 次抛是什么意思| 做书桌用什么板材好| 乙肝五项第二项阳性是什么意思| 低烧吃什么药| 甲状腺什么原因引起的| 荠菜什么时候播种最好| 勤去掉力念什么| 脑供血不足吃什么药效果好| 喝酒不能吃什么水果| ipad什么时候出新款| 柬埔寨为什么叫柬埔寨| 服中药期间忌吃什么| 什么叫屈光不正| 天珠是什么做的| 被蜜蜂蛰了涂什么药膏| 四川有什么好玩的| 化疗为什么要剃光头| 乳腺增生吃什么药效果好| 腰酸是什么原因女性| 摸头是什么意思| 白细胞计数偏高是什么原因| lotus是什么牌子| 惊厥是什么病| 身在其位必谋其职是什么意思| 749局是什么| 为什么早上起来口苦| 瘥是什么意思| 渐冻症是什么| 县团委书记是什么级别| 清明节在什么时候| 水垢是什么| evol是什么意思| 康波是什么意思| 总是口渴是什么原因| 氨咖黄敏胶囊是什么药| 毛手毛脚什么意思| 北边是什么生肖| 疾病是什么意思| pa是什么材质| 栀子花什么时候修剪| 脚气吃什么维生素| 满江红是什么植物| 储备是什么意思| 江西景德镇有什么好玩的地方| 眼睛老是肿着是什么原因造成的| 字读什么| 气体交换受损与什么有关| 六个坚持是什么| autumn是什么意思| 什么叫电解质| 泌尿系统由什么组成| 三级综合医院是什么意思| 什么头什么脑| 外阴病变有什么症状| 干咳无痰是什么原因引起的| lc是什么意思| 肺部条索影是什么意思| 子息克乏是什么意思| 鳊鱼吃什么食物| 两个月没有来月经了是什么原因| 奔豚是什么意思| 猿是什么动物| 激素吃多了对身体有什么副作用| 甘油三酯高是什么原因造成的| 血压低什么原因| 发烧应该吃什么药| 什么是匝道| CNN什么意思| 钧五行属什么| 吃完香蕉不能吃什么| 做月子可以吃什么| 梦见雪是什么意思| 中伤是什么意思| 尿酸高吃什么中药能降下来| 蛋白粉什么时间喝最好| 肝风内动吃什么中成药| 瑜伽是什么| 核磁共振是检查什么的| 挫是什么意思| 医疗保险是什么| 脾阳虚吃什么食物好| 排卵期出血吃什么药| 胎儿打嗝是什么原因| 绿是什么| 小孩办理护照需要什么材料| 灵魂伴侣是指什么意思| 户口本丢了有什么危害| 龟头有点痒擦什么药| 子宫内膜异位症有什么症状表现| 世交是什么意思| 三点水加分念什么| 杏花什么季节开| 高潮是什么感觉| 红眼病不能吃什么东西| 京酱肉丝用什么肉| 梵高属于什么画派| 屌丝男是什么意思| 发物是什么| 四月十九是什么星座| 为什么减肥一直减不下来| 可尔必思是什么饮料| 凤梨不能和什么一起吃| 猪咳嗽用什么药效果好| 咳血是什么病| 硕士研究生是什么意思| 鸡蛋干配什么菜炒好吃| 流鼻血是什么病| 手信是什么意思| 石头五行属什么| 1934年属什么| 嗓子疼低烧吃什么药| 咳嗽吃什么水果| 口头禅什么意思| 月经前一周是什么期| cini是什么意思| 盗汗是什么原因| 二级教授是什么意思| 最好的大学是什么大学| 嘴里发咸是什么原因| 花团锦簇是什么意思| 反流性食管炎吃什么中成药| miffy是什么意思| 小孩肚子疼拉肚子吃什么药| 新生婴儿吃什么奶粉| 月结是什么意思| 梦见看房子是什么预兆| 酒精胶是粘什么的| 书字五行属什么的| 牙龈起泡是什么原因| 葡萄球菌是什么| 纳财适合做什么| 头晕呕吐是什么原因引起的| 尔加玉读什么| 繁花似锦什么意思| venus是什么星球| 欧根纱是什么面料| 血滴子是什么意思| 射精出血吃什么药最好| 什么时候初伏第一天| 四两拨千斤是什么意思| 摘帽是什么意思| 梦见自己大出血是什么征兆| 子宫前位和子宫后位有什么区别| 手麻是什么病的预兆| 脚底疼是什么原因| 长期尿黄可能是什么病| 阴道干燥是什么原因| 养殖业什么最赚钱| 骷髅头是什么牌子| 丁卡是什么药| 肉蔻是什么样子| 百度

盆底脱垂有什么症状

Read(22404) update time(2025-08-04)

百度 余德辉要求,环保节能产业作为新兴产业,市场前景广阔。

Design pattern (Design pattern) is a set of classified and cataloged summary of code design experience that is used repeatedly, known to most people. The purpose of using design patterns is to reuse code, make the code easier to understand by others, and ensure code reliability. There is no doubt that design patterns are win-win for ourselves, others, and the system; design patterns make code writing truly engineering; design patterns are the cornerstone of software engineering, just like the structure of a building.


Design patterns (English design patterns) are solutions to recurring problems in object-oriented design. This term was introduced into computer science from the field of architectural design in the 1990s by Erich Gamma and others. The meaning of this term is controversial. Algorithms are not design patterns because algorithms address problem solving rather than design problems. Design patterns usually describe a set of classes and objects that interact closely with each other. Design patterns provide a common language for discussing software design so that the design experience of skilled designers can be grasped by novices and other designers. Design patterns also provide goals for software refactoring.

With the growing interest in design patterns in the software development community, some related monographs have been published, corresponding seminars have been held regularly, and Ward Cunningham invented WikiWiki to communicate design patterns. experience.

Tips: This tutorial will explain the concept of design patterns to you step by step through Java examples. So you need to know something about Javaknowledge.

Expression format

The format for expressing a software design pattern will vary according to different authors, such as divisions and names. The format of commonly used GoF description patterns is roughly divided into the following parts:

  • Pattern name: Each pattern has its own name, and the pattern name allows us to discuss our design.

  • Problem: There are specific occasions that recur during object-oriented system design that lead us to adopt a certain pattern.

  • Solution: The solution to the above problem, its content gives the various components of the design, their relationships, division of responsibilities and collaboration methods.

  • Alias: A pattern can have more than one name. These names should be noted in this section.

  • Motivation: In which case this pattern is used is the responsibility of the solution provided in this section (including the problem and the context).

  • Applicability: In which situations the model is applicable, the background of the model, etc.

  • Structure: This part of commonly used class diagrams and interaction diagrams illustrates this pattern.

  • Participants: This section provides a list of classes and objects used in this pattern and the roles they play in the design.

  • Cooperation: Describes the interaction between classes and objects in this mode.

  • Impact: The impact of adopting this model on other parts of the software system, such as the impact on the scalability and portability of the system. Impact also includes negative impacts. This section should describe the results, side effects, and trade-offs of using this pattern.

  • Implementation: This section should describe the implementation of the pattern, some solutions to the pattern, and Possible techniques for the pattern, or suggested ways to implement the pattern.

  • Example: Briefly describe how to use patterns in a programming language.

  • Known applications: Implementation examples known in the industry.

  • Related patterns: This part includes other related patterns and differences from other similar patterns.

Tip: Our Design Patterns tutorial will help you learn all about design patterns. If you have any questions, please go to PHP中文网community to ask your question, and enthusiastic netizens will answer it for you.

Pattern Principles

Everyone is starting to pay attention to design patterns. So, why do we use design patterns? Why should we design with so many design patterns?

To be honest, I really didn’t understand it before. Just watching everyone repeating "Design pattern" makes me feel a little weak. So I bought a book on the design patterns of the "Gang of Four", and it turned out that I didn't understand it at all: I seemed to understand it when I read it, but then I forgot about it after a while. Maybe it's because I'm relatively "stupid" :)) Recently, I have some insights. "It's better to be happy alone than to be happy together", I would like to share it with you, and I hope you can give me some advice!

Why should we advocate "Design Pattern"? The fundamental reason is to reuse code and increase maintainability.

So how can we achieve code reuse? The OO world has several principles from its predecessors: the "Open Closed Principal" principle, the Liskov substitution principle, and the synthesis and reuse principle. Design patterns implement these principles to achieve code reuse and increase maintainability.

  • Open-Closed Principle

This principle was proposed by "Bertrand Meyer". The original text is: "Software entities should be open for extension, but closed for modification". That is to say, the module should be open for extension but closed for modification. Modules should try to be expanded without modifying the original ("original", referring to the original code) code. So how to expand? Let's look at the "factory pattern": Suppose there is a guy in Zhongguancun who sells pirated disks and pornographic films. We design a "CD sales management software" for him. We should first design a "CD" interface. As shown in the picture: [pre]______________|<>|| CD ||_____________|| Sell() || ||_____________|[/pre] And pirated discs and pornographic films are its subcategories. The boy manages these discs through "DiscFactory". The code is:

publicclassDiscFactory{
publicstatic光盘
getDisc(Stringname){
return(光盘)Class.forName(name).getInstance();
}
}

Someone wants to buy a pirated disk, how to do it?

public class 小子{ public static void main(String【】 args){ CD d=DiscFactory.getDisc("Pirated Disc"); CD.Sell(); } }

If there is One day, this guy's conscience found out and he started selling genuine software. It doesn't matter, we just need to create another subcategory of "CD" called "genuine software". No need to modify the original structure and code. How about it? Open for extension, closed for modification. "Open-Closed Principle" The factory pattern expands specific products. Some projects may require more scalability. If you want to expand this "factory", it becomes the "abstract factory pattern".

  • Richter Substitution Principle

The Liskov substitution principle was proposed by "Barbara Liskov". If the parent class is called, it can be run if it is changed to a subclass. For example: CD d=new pirated disk(); d. sell(); If you want to change the "pirated disk" category to the "pornographic film" category, no problem, it can run completely. The Java compiler checks whether the program complies with the Liskov substitution principle. Do you still remember a principle of Java inheritance? The access rights of the override method of the subclass cannot be less than the access rights of the corresponding method of the parent class. For example, the access permission of the method "Sell" in "CD" is "public", then the "Sell" method in "Pirate Disc" and "Raw Film" cannot be protected or private, and the compilation will not pass. Why has to be this way? Think about it: if the "selling" method of "pirated disks" is private. Then the following code cannot be executed: CD d=new pirated disk(); d. sell(); It can be said that the Liskov substitution principle is a basis for inheritance and reuse.

  • Principle of synthesis and reuse

It means that inheritance should be used less and synthesis relationships should be used more. I once wrote a program like this: there are several classes that need to deal with the database, so I write a class for database operations, and then other classes that deal with the database inherit this. As a result, later, I modified a method of the database operation class, and all classes needed to be modified. "One move affects the whole body"! Object-oriented is to limit fluctuations to the smallest possible range.

In Java, you should try to program for Interface rather than implementation classes. This way, changing a subclass won't affect the code that calls its methods. Let each category have as little contact with others as possible, "Don't talk to strangers." In this way, if the city gate catches fire, the fish in the pond will not be harmed. Only when scalability and maintainability can be improved

After understanding these principles, and then looking at the design pattern, it is just about how to implement these principles on specific issues. Zhang Wuji learned Tai Chi, forgot all the moves, and defeated the "Two Elders Xuan Mi". It was said that he "had no moves in his mind". Design patterns can be described as tricks. If you first learn all the patterns, then forget all the patterns and do whatever you want, it can be called the highest state of OO. Haha, funny, funny! (JR)

Dependency Inversion Principle Abstraction should not depend on details, details should depend on

  • Dependency Inversion Principle

Program to the interface, not to the implementation. When passing parameters, or in combined aggregation relationships, try to reference higher-level classes. The main reason is that various concrete objects can be dynamically created when constructing objects. Of course, if some concrete classes are relatively stable, there is no need to make an abstract class as its parent class. This is superfluous. The interface isolation principle customizes services. Example, each

  • Interface Isolation Principle

A role, no more, no less, don’t do things you shouldn’t do, and do what you should do Abstract classes have to do everything. Abstract classes will not have instances

  • Abstract class

Classes are inherited by subclasses and generally contain common attributes and methods of this system. Note: In a good inheritance relationship, only leaf nodes should be concrete classes, and other nodes should be abstract classes, which means that concrete classes are not inherited. Put as much common code as possible into abstract classes. 7 Demeter's Law of Minimum Knowledge Principle. Don't talk to strangers.

Content covered by this design pattern tutorial manual

This design pattern tutorial covers the introduction of all design patterns, including Factory Pattern, Abstract Factory Pattern, Singleton Pattern (Singleton Pattern), Builder Pattern (Builder Pattern), Prototype Pattern (Prototype Pattern), etc.

Tips: Each chapter of this tutorial contains many Java examples, which will help you better learn and understand design patterns.

Latest chapter


传输对象模式 2025-08-04
服务定位器模式 2025-08-04
拦截过滤器模式 2025-08-04
前端控制器模式 2025-08-04
数据访问对象模式 2025-08-04
组合实体模式 2025-08-04
业务代表模式 2025-08-04
MVC 模式 2025-08-04
党工委书记是什么级别 什么字五行属水 脚底发麻是什么病的前兆 杨颖原名叫什么 知见是什么意思
1987年出生属什么 葳是什么意思 劲头是什么意思 94年属什么的 阴道干涩是什么原因
王八蛋是什么意思 绿色加什么颜色是蓝色 什么颜色显白 什么茶 护理部是干什么的
炳是什么意思 移动增值业务费是什么 颈部有肿块挂什么科 146是什么意思 垂体泌乳素高是什么原因
甘油三酯高吃什么食物好hcv8jop0ns3r.cn 血管炎吃什么药hcv8jop4ns9r.cn 报恩是什么意思hcv7jop9ns9r.cn 线束厂是做什么的hcv9jop5ns8r.cn 羊水多对胎儿有什么影响hcv9jop0ns3r.cn
83年属什么96micro.com 6月13日是什么日子mmeoe.com 阳虚是什么hcv8jop9ns1r.cn 妇科检查清洁度3度什么意思hcv7jop7ns0r.cn 不昧因果是什么意思hcv9jop3ns0r.cn
plus是什么意思hcv7jop7ns0r.cn maby什么意思hcv9jop6ns3r.cn 荨麻疹是什么原因引起aiwuzhiyu.com 金刚芭比什么意思hcv8jop8ns8r.cn 二月初二是什么星座hcv8jop8ns3r.cn
人生的意义是什么hcv9jop4ns1r.cn 夫人是什么意思hcv9jop6ns0r.cn 性格好是什么意思hcv9jop4ns4r.cn 支气管炎能吃什么水果hcv8jop5ns6r.cn 吃多了拉肚子是什么原因hcv9jop1ns8r.cn
百度