了解设计的优势
patterns
模式
Creating an object-oriented design is a tough task. This is because we have several
创建面向对象的设计是一项艰巨的任务。这是因为我们有几个
important elements to think about with regard to the scenario that we’ll work in and the
关于我们将要工作的场景和
problem we’ll solve. This includes defining the appropriate objects that we need to create in
我们要解决的问题。这包括定义需要在其中创建的适当对象
order to reach the solution; defining the granularity of objects and looking at what
以达到解决方案;定义对象的粒度并查看
interfaces we need to create. These tasks need to be addressed during the creation process
我们需要创建的接口。这些任务需要在创建过程中解决
in design. Objects can be created to represent a real-world object or to represent a process
在设计上。可以创建对象来表示真实世界的对象或表示过程
with its algorithms and responsibilities. Furthermore, we even need to consider the number
以及它的算法和职责。此外,我们甚至需要考虑这个数字
of objects, their size, and the interface we need to access.
对象的大小,以及我们需要访问的接口。
Design patterns are great tools for helping us to identify classes and objects that don’t
设计模式是一个很好的工具,它可以帮助我们识别出不存在的类和对象
represent real-world objects and objects that are less-obvious abstractions. Moreover,
表示真实世界的对象和不太明显的抽象对象。而且,
design patterns help us to apply the finest granularity to objects and they also allow us to
设计模式帮助我们将最细的粒度应用于对象,它们也允许我们
analyze a problem and solution as a model. Design patterns make the design flexible,
分析问题和解决方案作为模型。设计模式使设计更加灵活,
providing a decoupling between classes and objects. They also provide the ability to
提供类和对象之间的解耦。它们还提供了
organize solutions, allowing delegate responsibilities to classes with the best way.
组织解决方案,允许以最佳方式将职责委派给类。
Building software is an expensive process for companies because it requires capable
对于公司来说,构建软件是一个昂贵的过程,因为它需要有能力的
professionals and infrastructure to build and maintain the software. Design patterns, with
构建和维护软件的专业人员和基础设施。设计模式,使用
their flexibility and decoupled design, make maintenance easy and therefore decrease its
他们的灵活性和解耦设计,使维护容易,因此减少了它
cost.
成本。
Understanding the basic design patterns of
了解 基础的设计模式
the Java world
Java世界
All GoF patterns have a good purpose and solve major problems of object-oriented design,
所有GoF模式都有很好的用途,解决了面向对象设计的主要问题,
but some patterns are most commonly used in the Java and Java EE ecosystem. In this book,
但是有些模式在Java和javaee生态系统中最常用。在这本书里,
these patterns are treated as basic design patterns because they are most commonly used to
这些模式被视为基本设计模式,因为它们最常用于
implement solutions on Java’s APIs, frameworks, and algorithms. Consequently,
在Java的api、框架和算法上实现解决方案。因此,
understanding these patterns will help us to understand these APIs, frameworks, and
理解这些模式将有助于我们理解这些api、框架和
algorithms, and we’ll, in turn, be able to create a better solution using Java. These patterns
算法,然后我们将能够使用Java创建一个更好的解决方案。这些模式
are Singleton, Abstract Factory, Facade, Iterator, and Proxy
是Singleton、抽象工厂、Facade、Iterator和Proxy
Explaining Singleton
解释单例
In a software project, in some solutions, we may want to ensure that a class has only one
在软件项目中,在某些解决方案中,我们可能希望确保一个类只有一个
instance of an object throughout the project and that this object is accessible at any point in
对象的实例,并且此对象在
the project. Creating a global instance or static instance will not ensure that this class will
项目。创建全局实例或静态实例不能确保该类
not be used at another point in another instance. The best way to solve this is by using the
不能在另一个实例的另一个点上使用。解决这个问题的最好方法是使用
Singleton pattern, which ensures that there is only one instance of a class in the entire
单例模式,它确保整个类中只有一个实例
project. In the following diagram, we are showing the structure of Singleton and how it is
项目。在下面的图表中,我们展示了Singleton的结构以及它是怎样的
designed:
设计:
完结
Redis基于内存,常用作于缓存的一种技术,并且Redis存储的方式是以key-value的形式。Redis是如今互联网技术架构中,使用最广泛的缓存,在工作中常常会使用到。Redis也是中高级后端工程师技术面试中,面试官最喜欢问的问题之一,因此作为Java开发者,Redis是我们必须要掌握的。
Redis 是 NoSQL 数据库领域的佼佼者,如果你需要了解 Redis 是如何实现高并发、海量数据存储的,那么这份腾讯专家手敲《Redis源码日志笔记》将会是你的最佳选择。
作为Java开发者,Redis是我们必须要掌握的。
Redis 是 NoSQL 数据库领域的佼佼者,如果你需要了解 Redis 是如何实现高并发、海量数据存储的,那么这份腾讯专家手敲《Redis源码日志笔记》将会是你的最佳选择。
[外链图片转存中…(img-WnStm17U-1714323206341)]