- 博客(11)
- 收藏
- 关注
原创 抽象工厂设计模式
抽象工厂 简单介绍 抽象工厂模式属于创建型设计模式,是工厂模式的一种实现。工厂方法是按产品级维度对工厂进行抽象,而抽象工厂是按产品族维度对工厂进行抽象。产品级可以简单的理解为具体的单个产品,产品族则是有多个产品构成。如苹果公司生产的手机、手表等单个产品可以简单理解为产品级,这些苹果公司生产的这一系列产品(手机、手表)放在一起则可以简单理解为一个产品族。 使用场景 业务中需要针对产品族维度...
2019-11-15 17:06:48
209
原创 工厂方法设计模式
工厂方法 简单介绍 工厂方法模式属于创建型设计模式,是工厂模式的一种实现。工厂方法模式将工厂类进行抽象,由具体的工厂决定需要生产(实例化)的类。工厂方法模式将对象的实例化推迟到子类。 使用场景 想要隔离具体实现,让客户端只通过接口便能得到想要的实例对象。 把创建对象的职责集中管理和控制 。与简单工厂不同的是,当需要生产新的对象类型时,简单工厂需要修改工厂类的内容,而工厂方法则需要新增一个...
2019-11-12 21:50:11
197
原创 简单工厂设计模式
简单工厂设计模式 简单介绍 简单工厂模式属于创建型设计模式,是工厂模式的一种实现。简单工厂模式中,专门有一个负责创建各类产品实例的对象(即工厂对象),并提供一个静态方法(故简单工厂有称为静态工厂),返回创建好的实例对象。 使用场景 想要隔离具体实现,让客户端只通过接口便能得到想要的实例对象。 把创建对象的职责进行集中、统一的管理和控制 。 场景举例 JDK中的Calendar类,根据...
2019-11-09 15:16:55
236
原创 单例设计模式
单例设计模式 简单介绍 通过一定的方法,保证在整个软件系统(一个进程)中,某个类只有唯一的对象实例,并且该对象实例可以通过此类的类方法进行获取 使用场景 需要频繁的进行创建和销毁对象,创建对象耗时过多或消耗资源过多,但又经常使用的对象,如工具类对象、频繁访问数据库或文件的对象(数据源、session工厂)等 场景举例 Hibernate中的SessionFactory充当数据存储源的...
2019-11-09 11:00:25
209
原创 设计模式原则
设计模式原则 设计模式意义 增加代码重用性,尽可能复用已有功能代码 增加代码可读性,便于他人理解 提升代码可扩展性,能够做到拥抱需求变化 提升代码可靠性,新增功能时,不影响已有的业务功能 使得代码具备高内聚、低耦合等特性 七大设计原则 单一职责 维基百科 在面向对象编程领域中,单一功能原则(Single responsibility principle)规定每个...
2019-11-09 10:55:45
245
原创 6. ZigZag Conversion
Description The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N ...
2019-06-15 16:54:12
158
原创 5. Longest Palindromic Substring
Description Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Difficulty Medium Example1 Input: "babad" Output: "bab" Note: "aba" is ...
2019-06-15 16:43:24
172
原创 4. Median of Two Sorted Arrays
Description There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assume...
2019-04-28 23:03:58
124
原创 3. Longest Substring Without Repeating Characters
Description Given a string, find the length of the longest substring without repeating characters. Difficulty Medium Example1 Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the l...
2019-04-27 13:27:32
137
原创 2. Add Two Numbers
Description You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers ...
2019-04-24 16:38:11
147
原创 1. Two Sum
Description Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not u...
2019-04-24 15:51:36
108
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅