知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

      • Theory:The concept of patterns
        • Code design
        • Design patterns
        • Software design patterns and related concepts
        • Why should I know design patterns?
        • Caveats
        • Conclusion
      • Theory:Structural of design patterns
      • Theory:Decorator pattern
      • Theory:Decorator
    • Web

    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • Design pattern
Jim
2022-10-12
目录

Theory:The concept of patterns

# Code design

If you are reading this, you must be really interested in programming. It doesn't matter whether you are an experienced developer, just starting your career, or still working on the basics; what really matters is that you are curious, so welcome.

To begin with, let's talk about code design*.* In general, the design of your code is about expressing your ideas clearly to your teammates, colleagues, and clients. We can compare code to text: if you put the lines in the right order and make the structure clear, it will be much easier to explain and understand the text later. From an engineering point of view, your code is well-designed if you can agree with the following statements:

\1) When you make a small change, it does not produce a ripple effect elsewhere in the code. \2) Your code is easy to reuse. \3) It is easy to maintain your code after release.

# Design patterns

In application development, the design of code has to match the problem and be general enough in order to fit all the requirements that may arise in the future. Everyone tries to find more elegant, suitable and flexible solutions that can also be reused. Here is where design patterns come into play: these are repeatable solutions to common problems that developers face. Design patterns even have names! For example, if you want to confine yourself to just one instance of a class, Singleton pattern is going to be the best choice; if you see family relations between objects and you want to encapsulate creational processes, you should use AbstractFactory, etc.

As a rule, examples of well-structured object-oriented architecture make use of patterns a lot. When a suitable pattern is used, it tells us that the developer has really paid attention to typical interactions between elements in the system. As a result, the architecture of an application becomes easier to understand.

Being so useful, design patterns have made it onto many programmers' bookshelves: one of the most famous examples is the book Design Patterns: Elements of Reusable Object-Oriented Software (opens new window). You probably heard about its authors, "Gang of Four", which is frequently abbreviated as "GoF". Today it is considered one of the classic books on software design and programming. You may check it out to deepen your understanding or proceed directly to practical learning here.

Note that in this topic we will only consider object-oriented design patterns.

img

# Software design patterns and related concepts

A great thing about patterns is that they help you not to waste your time reinventing the wheel so you can spend it on developing cool features instead. The structure of design patterns is strict: describe the problem, the solution, when to apply the solution, and its consequences. Theoretically, you can combine a few patterns and create your own monster pattern that contains, for example, Builder, Abstract Factory and Decorator simultaneously. However, as you will see from the following topics, it's better to avoid such monsters because patterns have already been well-grouped for you. In other words, don't get too excited, it's really better to use them one at a time.

Using patterns does not require any specific programming language skills or striking imagination. Patterns are also language-independent: even though they can be implemented differently in different languages, the general idea of each pattern is common for all of them. That means that it's possible for you to speak the language of architecture with your colleagues even if they work with different technologies.

# Why should I know design patterns?

Here is a list of quite convincing reasons to get familiar with design patterns:

  • Patterns provide tested and commonly used solution templates for design problems; you don't have to invent anything!
  • Patterns improve flexibility and maintainability of object-oriented systems, which makes it easier to react to changing requirements.
  • Patterns can speed up the development process.
  • Patterns are a universal vocabulary that allows developers to describe a program design using a set of well-known identifiable concepts.
  • Patterns are often used in standard libraries and frameworks.
  • You can find patterns in the source codes of many applications and quickly understand how they work, instead of reading thousands of lines of code.

# Caveats

In order to achieve flexibility, design patterns usually introduce additional levels of indirectness, which in some cases may complicate the resulting designs and hurt application performance. In other words, even though patterns are supposed to make things easier for you, they may also become an unnecessary complication if applied unwisely. Beginner developers may try to apply patterns everywhere, even in situations where a simpler code would do just fine. Look (opens new window) how design patterns can complicate even the simplest "Hello, World" program.

To avoid misusing the patterns, you should apply them wisely and be able to correctly adapt them to your problem and language.

# Conclusion

When you master the principles of working with patterns so that after successfully applying them you scream "Eureka!" without any doubt in your thoughts, your perception of object-oriented programming will probably change once and for all. In the following topics, you will learn about Creational, Structural and Behavioral design patterns. Be concentrated and attentive: these matters are quite advanced. Happy coding!

编辑 (opens new window)
#Pattern
上次更新: 2022/10/12, 17:01:25
Theory:Dynamic array
Theory:Structural of design patterns

← Theory:Dynamic array Theory:Structural of design patterns→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式