西维蜀黍

【Design Pattern】Structural — Decorator

定义

装饰器模式以对客户端透明的方式,给一个对象附加上更多的责任(以实现对对象功能的扩展)。

换言之,客户端并不会觉得对象在装饰前和装饰后有什么不同。装饰器模式可以在不需要创造更多子类的情况下,将对象的功能加以扩展。这就是装饰器模式的模式动机。

  ...


【Spring】Spring 中的 IoC

什么是Spring?

Spring 是个Java企业级应用的开源开发框架。Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用。Spring框架目标是简化Java企业级应用开发,并通过POJO为基础的编程模型促进良好的编程习惯。

使用Spring框架的好处是什么?

  • 轻量:Spring 是轻量的,基本的版本大约2MB。

  • 控制反转:Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依赖的对象们。

  • 面向切面的编程(AOP):Spring支持面向切面的编程,并且把应用业务逻辑和系统服务分开。

  • 容器:Spring 包含并管理应用中对象的生命周期和配置。

  • MVC框架:Spring的WEB框架是个精心设计的框架,是Web框架的一个很好的替代品。

  • 事务管理:Spring 提供一个持续的事务管理接口,可以扩展到上至本地事务下至全局事务(JTA)。

  • 异常处理:Spring 提供方便的API把具体技术相关的异常(比如由JDBC,Hibernate or JDO抛出的)转化为一致的unchecked 异常。

  ...


【Programming】面向切面编程(AOP)

Aspect Oriented Programming (AOP)

背景

AOP(Aspect Oriented Programming),即面向切面编程,可以说是**OOP(Object Oriented Programming,面向对象编程)**的补充和完善。

  ...


【Design Pattern】Structural - Proxy/Wrapper

代理模式(Proxy Pattern)

In computer programming, the proxy pattern is a software design pattern.

Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.

In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be forwarding to the real object, or can provide additional logic.

In the proxy, extra functionality can be provided, for example caching when operations on the real object are resource intensive, or checking preconditions before operations on the real object are invoked. For the client, usage of a proxy object is similar to using the real object, because both implement the same interface.

  ...


【Java】泛型(Generics)

什么是泛型(generics)

泛型(generics)是指参数化类型的能力。可以定义带泛型类型的类或方法,随后编译器会用具体的类型来代替它。

  ...