Skip to Content
Python设计模式(第2版)
book

Python设计模式(第2版)

by Posts & Telecom Press, Chetan Giridhar
February 2024
Intermediate to advanced
139 pages
1h 42m
Chinese
Packt Publishing
Content preview from Python设计模式(第2版)

第9章 模型—视图—控制器——复合模式

在上一章中,我们介绍了模板方法设计模式,该模式的子类可以重新定义算法的具体步骤,从而实现了灵活性和代码重用。同时,我们还讲解了模板方法以及如何使用它来构造具有一系列步骤的算法。之后,我们讨论了该模式的UML图及其优缺点,在常见问答部分进行了知识拓展,最后进行了总结。

在本章中,我们将讨论复合模式。我们将介绍模型—视图—控制器(MVC)设计模式,并讨论如何将其应用于软件应用程序的开发。同时,我们将提供相应的示例用例,以及基于Python v3.5的代码实现。

在本章中,主要涉及以下主题:

  • 复合模式和模型—视图—控制器的简介;
  • MVC模式及其UML图;
  • Python v3.5代码实现的真实用例;
  • MVC模式的优点和缺点;
  • 常见问答。

在本章结束时,我们将对所有内容进行总结。

在本书中,我们探索了各种设计模式。正如我们所看到的,设计模式可分为三大类:结构型、创建型和行为型设计模式。同时,我们还给出了每种类型的相应示例。然而,在软件实现中,模式并是不孤立地工作的。对于所有软件设计或解决方案来说,很少出现仅利用一种设计模式来实现的情况。

实际上,这些模式通常需要同时使用并加以组合,以实现特定的设计解决方案。根据GoF的定义,“复合模式将两个或更多模式组合成解决常见或普遍性问题的解决方案。复合模式不是同时使用的一组模式,而是一个问题的通用解决方案。

接下来,我们将考察模型—视图—控制器复合模式,该模式是复合模式的最佳示例,并且已经在许多设计解决方案中应用多年了。

MVC不仅是一种实现用户界面的软件模式,同时也是一种易于修改和维护的架构。通常来说,MVC模式将应用程序分为3个基本部分:模型、视图和控制器。这3个部分是相互关联的,并且有助于将信息的处理与信息的呈现分离开来。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python面向对象编程指南

Python面向对象编程指南

Posts & Telecom Press, Steven F. Lott
算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)
人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar

Publisher Resources

ISBN: 9781835880043