public abstract class Aggregate{
public abstract Iterator createIterator();
}
声明了创建构造器的抽象方法
迭代器接口的实现类
public class ClassroomIterator implements Iterator{
private List
内部包含两个变量list和offset,通过传入list的方式进行初始化。实现迭代器接口相关方法。
Aggregate实现类
public Classroom extends Aggregate{
private List list = new ArrayList();
public ConcreateAggregate ( List list){
this.list = list;
}
public Iterator createIterator(){
return new ClassroomIterator(this);
}
}
client
Student s1 = new Student("leo");
Student s2 = new Student("mary");
List list = new ArrayList<>(){{add(s1);add(s2);}};
Classroom cr = new Classroom(list);
Iterator iterator = cr.createIterator();
while(iterator.isDone){
System.out.println(iterator.next)
}
public interface OldInterface{
void doSomething();
}
新接口
public interface NewInterface{
void doSomething();
}
适配器
public class AdapterParttern implements NewInterface{
private OldInterface oldInterface;
public AdapterParttern(OldInterface old){
this.oldInterface = old;
}
public void doSomething(){
oldInterface.doSomething();
}
}
模板模式
应用场景,避免重复代码
UML
主要角色
模板
public abstract class MorningTemplate{
protected void do(){
getUp();
washingFace();
eat();
}
public abstract void getUp();
public abstract void washingFace();
public abstract void eat();
}
实现
public class JasonMorning extends MorningTemplate{
public void getUp(){
System.out.println("getUp");
}
public void washingFace(){
System.out.println("washing face");
}
public void eat(){
System.out.println("eat");
}
}
客户端
public class client{
public static void main(String[] args){
MorningTemplate jason = new JasonMorning();
jason.do();
}
}
interface Product{
void make();
}
class SpecialProduct implements Product{
@Override
public void make(){
System.out.println("make a special product。。")
}
}
class ProductFactory(){
public Product createProduct(){
return new SpecialProduct();
}
}
class client{
public static void main(String[] args){
Product product = ProductFactory.createProduct();
product.make();
}
}
工厂方法模式
interface Product{
void make();
}
class SpecialProduct implements Product{
public SpecialProduct(){
System.out.println("create special product");
}
@Override
public void make(){
System.out.println("make a special product")
}
}
interface ProductFactory{
Product create();
}
class SpecialProductFactory implements ProductFactory{
private static final SpecialProductFactory INSTANCE = new SpecialProductFactory();
private SpecialProductFactory(){};
public static SpecialProductFactory getInstance(){
return INSTANCE;
}
@Override
public Product create(){
return new SpecialProduct();
}
}
public class ClientDemo{
public static void main(String[] args){
Product product = SpecialProductFactory.getInstance.create();
product.make();
}
}
抽象工厂模式
单例模式
单例模式比较简单,这里就不声明角色和UML图了。直接看代码吧
饿汉模式
public class Singleton{
private static final Singleton INSTANCE = new Singleton();
private Singleton(){}
public static Singleton getInstance(){
return INSTANCE;
}
}
线程不安全的懒汉模式
public class Singleton{
private static Singleton instance;
private Singletion(){}
public static Singleton getInstance(){
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
双重检查锁的懒汉模式
public class Singleton{
private static Singleton instance;
private Singletion(){}
public static Singleton getInstance(){
if (instance == null) {
synchronized(Singleton.class){
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
内部类模式
public class Singleton{
private static Singleton instance;
private Singletion(){}
private static class SingletonHolder{
private static final INSTANCE = new Singleton();
}
public static Singleton getInstance(){
return SingletonHolder.INSTACE;
}
}
package com.zhss.designpattern.proxy;
/**
* @description: 静态代理模式
* @projectName: designpattern
* @see: com.zhss.designpattern.Proxy
* @author: 祁琦
* @createTime: 2020/1/14 13:49
* @version: 1.0
*/
public class StaticProxyPattern {
public static void main(String[] args) {
Star jay = new Jay();
Star proxy = new ProxyStar(jay);
proxy.sing();
}
public interface Star {
void sing();
}
public static class Jay implements Star {
@Override
public void sing() {
System.out.println("周杰伦正在唱歌");
}
}
public static class ProxyStar implements Star {
private Star star;
public ProxyStar(Star star) {
this.star = star;
}
@Override
public void sing() {
System.out.println("唱歌之前的准备工作");
star.sing();
System.out.println("休息休息一下");
}
}
}
/* system out */
/*
唱歌之前的准备工作
周杰伦正在唱歌
休息休息一下
*/
参考:http://blog.csdn.net/qingfeilee/article/details/7052736
org.hibernate.NonUniqueResultException: query did not return a unique result: 2
在项目中出现了org.hiber
由Oracle通信技术部门主导的演示项目并没有在本月较早前法国南斯举行的行业集团TM论坛大会中获得嘉奖。但是,Oracle通信官员解雇致力于打造一个支持零干预分配和编制功能的网络即服务(NaaS)平台,帮助企业以更灵活和更适合云的方式实现通信服务提供商(CSP)的连接产品。这个Oracle主导的项目属于TM Forum Live!活动上展示的Catalyst计划的19个项目之一。Catalyst计
Spring MVC提供了非常方便的文件上传功能。
1,配置Spring支持文件上传:
DispatcherServlet本身并不知道如何处理multipart的表单数据,需要一个multipart解析器把POST请求的multipart数据中抽取出来,这样DispatcherServlet就能将其传递给我们的控制器了。为了在Spring中注册multipart解析器,需要声明一个实现了Mul
the CollabNet user information center http://help.collab.net/
How do I create a new Wiki page?
A CollabNet TeamForge project can have any number of Wiki pages. All Wiki pages are linked, and
package beautyOfCoding;
import java.util.Arrays;
import java.util.Random;
public class MaxSubArraySum2 {
/**
* 编程之美 子数组之和的最大值(二维)
*/
private static final int ROW = 5;
private stat
示例程序,swap_1和swap_2都是错误的,推理从1开始推到2,2没完成,推到3就完成了
# include <stdio.h>
void swap_1(int, int);
void swap_2(int *, int *);
void swap_3(int *, int *);
int main(void)
{
int a = 3;
int b =
同步工具类包括信号量(Semaphore)、栅栏(barrier)、闭锁(CountDownLatch)
闭锁(CountDownLatch)
public class RunMain {
public long timeTasks(int nThreads, final Runnable task) throws InterruptedException {
fin
不止一次,看到很多讲技术的文章里面出现过这个词语。今天终于弄懂了——通过朋友给的浏览软件,上了wiki。
我再一次感到,没有辞典能像WiKi一样,给出这样体贴人心、一清二楚的解释了。为了表达我对WiKi的喜爱,只好在此一一中英对照,给大家上次课。
In computer science, bleeding edge is a term that