iluwatar 设计模式

iluwatar 设计模式

行为

acyclic-visitor

目前我常用多种调用, 某个实现类接口A,a.handle(Context ctx);

改变调用观念,创建不一样的行为h,创建不一样的上下文c, 正常观念 h.handle©跟上面一样,

但这个 c.accept(h) -> 细节 -》 h.handle©;中间多了一层。目前来看可以避免不必要的ctx透传,外加接口约束

context-object

bytecode

虚拟机解析字符串指令,switch-case + stack

chain-of-responsibility

client-session(平平无奇为每一个client创建session存数据)

collecting-parameter(无用)

看到无用又回头看了看代码,真没用。别去想了

converter

不单单写几个转换方法,提升为一个接口

Curiously Recurring Template Pattern

Delegation

不直接调用业务类

Dirty Flag(IO或Cache标记)

Double Buffer

旧垃圾回收 新生代

Feature Toggle

基于标量或则唯一标记。执行不一样的策略

Filterer

stream的filter过于面向对象,如果filter后的数据需要有很复杂的业务逻辑。可以采取这种设计模式。用一个对象包装filter,filter完创建一个新的对象。

Fluent Interface

The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API. Those interfaces tend to mimic domain specific languages, so they can nearly be read as human languages.

Game Loop

FrameBasedGameLoop(每tick一次执行一次)

VariableStepGameLoop(每tick一次执行一次带消耗时间)

FixedStepGameLoop(每tick一次执行一次带固定消耗时间)

Update Method (同上)

跟FrameBasedGameLoop一样 tick all entity,slg tick

Health check

Identity Map

The Identity Map design pattern in Java aims to ensure that each object gets loaded only once by keeping every loaded object in a map, enhancing database performance and memory management.

Interpreter

栈处理公式翻译

Mute Idiom(try catch)

Notification(代码跟图不适配,可在研究)

Null Object

Parameter Object(说是结构但我更认为是行为)

一个有默认值的上下文。但是这个上下文会用到其他方法里面(这不好吧)

Partial Response

获取某个数据的局部数据,但是对我来说更多写多一条协议

Pipeline

Netty 专属

Poison Pill(说是并发,但更像行为)

The Poison Pill design pattern is used to gracefully shut down a service or a producer-consumer system by sending a special message (the "poison pill") to message queue which indicates that no more messages will be sent, allowing the consumers to terminate.

终结Event

Private Class Data(说是结构,但更像行为)

优先使用不可变类

Value Object(说是结构,但更像行为)

不可变类,lombok @Value

Property

Map + Null Object

Servant(结构->行为 卢哥的什么er)

Servant offers some functionality to a group of classes without defining that functionality in each of them. A Servant is a class whose instance provides methods that take care of a desired service, while objects for which the servant does something, are taken as parameters.

Specification

state

Strategy

我一般不要左边的类,Map<Key,Strategy>

Template Method (同上)

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

Template View(同上)

Subclass Sandbox

Unit of Work(数据->行为)

register把action添加队列,就是一个对于全部对象入库好的方式

Visitor

创建

builder(不用说了吧)

abstract-factory

Map<FactoryType, FactoryInterface>

dependency-Injection

execute-around

factory

Factory Kit

Factory Method

Multiton

Object Pool

Prototype

The Prototype pattern is a creational design pattern in software development. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used to: - avoid subclasses of an object creator in the client application, like the abstract factory pattern, does. - avoid the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword)

registry

Singleton

推荐枚举

Step Builder

Type Object

结构

bloc(类似状态机)

business-delegate

像mvc结构,control -> service -> dao control不直接操作dao

clean-architecture

像mvc结构,control -> service -> dao control不直接操作dao,跟business-delegate不懂,这了的service包含多个dao,

command-query-responsibility-segregation

像mvc结构,control -> service -> dao control不直接操作dao,其中 control, service都是接口

component

组合大于继承

composition

description: "Explore the Composite Design Pattern in Java. Learn how to compose objects into tree structures to represent part-whole hierarchies, making it easier to treat individual objects and compositions uniformly. Ideal for graphical user interfaces, file systems, and organizational structures."

继承或实现同一个接口,然后嵌套组合起来调用

composition-entity

类似门面模式,将有关联的对象封装起来

composition-view

java web 暂时不管。

data-bus

event-aggregator

Event-Driven Architecture

event-bus

Decorator

A impl 接口, B impl 接口, 同时 A组成B

Domain Model

类包含了 业务逻辑 和 CRUD

Event Sourcing

感觉内部战斗可以使用这个方式记录战斗操作,玩家服对于资源也可以用上

Facade

对于复杂业务的一个封装

Session Facade

同上不过是Service层面上的,Facade是业务层面。不在同一层级,大差不差

Flux

链接: facebook flux

注册,回调

Flyweight

大量对象集合创建,统一分配。

Front Controller

统一请求入口,然后分开请求后的业务细节

Gate Way(类似Front Controller)

Hexagonal(六边形)

永远有一层胶水层

Intercepting Filter(过滤链)

Layered Architecture

Model-View-Controller (MVC)

Controller包含model 和 view, model是数据, view是页面。维护控制双方

controller收到新的model渲染view

Model-View-ViewModel

相对于controller,viewmodel分离了 model 和 view耦合在controller的逻辑

Model-View-Intent (MVI)

Model-View-Intent is a pattern for implementing user interfaces. Its main advantage over MVVM which it closely mirrors is a minimal public api with which user events can be exposed to the ViewModel. In case of the MVI every event is exposed by using a single method with 1 argument which implements UserEvent interface. Specific parameters can be expressed as its parameters.

Model-View-Presenter (MVP)

每一个view都有一个presenter来控制

Presentation Model(同上大差不差吧)

Page Controller

Service to Worker

虽说是页面的设计模式,细看想是卢哥的gameCmd。全部请求到一个地方,通过已经注册的gameCmd调用对应模块的业务。然后返回给客户端

Money(封装了一个钱的对象处理金额细节)

Monolithic

Observer

Proxy

Publish-Subscribe

Queue-Based Load Leveling

Role Object

Separated Interface

Service Layer

Special Case

业务处理的时候,一般检验不过直接return,不如在带有返回值的业务方法,使用该模式

不直接return null,return 一个对象,代表这次处理的结果。比return 更好

twin

Virtual Proxy

线程

active-object

对象持有线程独立运行任务,遇到的项目大多都是玩家对象持有队列,归去其中一个线程执行

actor-model

actor -> sendMsg -> mailBox <- takeMsg <-otherActor

async-method-invocation(太旧了可以不用管)

每一个任务创建一个线程去处理,请求任务进度的时候 await

backpressure(reactor中的背压 )

背压是反应流中的一个重要概念,可以理解为,生产者可以感受到消费者反馈的消费压力,并根据压力进行动态调整生产速率

subscribe -》我能处理10个 -》 publisher -》按一定规则发送10个业务

balking(慢行 太旧了可以不用管)

多个线程操作一个对象,对象上锁+状态,状态不对不执行

Double-Checked Locking

Event-Based Asynchronous

线程有点粗暴了,可以采用线程池提供异步或则同步的解决方式。但是一般抛出事件异步一下或则立即执行就好了,暂时没想到延迟抛出的使用场景

Event Queue

有一个message数组,int tail, int head两个字段。分别由两个线程控制,生产线程控制head++,消耗线程控制tail++

Fan-Out/Fan-In

The Fan-Out/Fan-In design pattern in Java aims to improve concurrency and optimize processing time by dividing a task into multiple sub-tasks that can be processed in parallel (fan-out) and then combining the results of these sub-tasks into a single outcome (fan-in).

可以用在加载配表,基于不同玩家缓存策略也可以尝试采用。但是因为fan-in需要等待全部任务完成。可能只适用于启服的时候少量拉取活跃玩家的数据

Guarded Suspension

Half-Sync/Half-Async

一个任务里面,可能存在不需要异步的操作,譬如检验。如果校验不过就不需要后续的异步操作。可以节省一些资源

Leader-Followers

一组Worker里面有一个leader,每当任务过来交给leader做,同时移除leader,当任务做完,先前的leader以worker身份重新加入回worker组

Lockable-object

Monitor

synchronize方法。底层就是 monitor in/out

Optimistic Offline Lock

要确保version更新是一致的,不能两个线程同时get出来同一个versionId

Producer-Consumer

Promise

The Promise design pattern is used to handle asynchronous operations by providing a placeholder for a result that is initially unknown but will be resolved in the future.

Reactor

重点在于EventHandler可以采取不同的方式处理handler,但这不是reactor的重点。响应式变成,基于事件驱动。netty loop

Thread-Pool Executor

Version Number

CAS version 或 synchronize get version 。比较version是否合适更新

函数

callback

传个lambda过去回调

collection-pipeline

流式编程

combinator

command (跟callback一样)

currying

Function Composition(多思考函数的组合)

Lazy Loading

Monad(很漂亮检验方式)

Trampoline

使用Stream.iterate把递归变为迭代

数据

abstract-document

用map嵌套map存全部数据

data-access-object(dao)(跟data-mapper没多大区别)

data-mapper(跟dao没多大区别)

Table Module

一个类包含了一个数据对象的全部操作,业务逻辑,事务sql操作等等,mapper低级版本

Repository


Resource Acquisition Is Initialization (RAII)

Serialized Entity

Serialized Entity Pattern allow us to easily persist Java objects to the database. It uses Serializable interface and DAO pattern. Serialized Entity Pattern will first use Serializable to convert a Java object into a set of bytes, then it will using DAO pattern to store this set of bytes as BLOB to database.

Serialized LOB(Large Object)

BlobSerializer

ClobSerializer

转换后在入库,出库时候解析

Sharding

一个map存储的数据大了,拆分多个小map

HashShard(hash 的分配)

LookupShard(随机分配唯)

RangeShard(类型分配)

Table Inheritance Pattern

Single Table Inheritance

一个表存一个类的多态数据,car truck 两个类的数据都存在 Vehicle的表里面。

感觉没啥好处,car 和 truck又不能转换。数据量大了还要拆分出来

Table Inheritance

有一个总表存数据,字表存对应的关键key

Transaction Script

一个service完成 crud全部过程,包括事务,接口

重构(游戏里面重构多数直接重写了)

adapter

A -》new B(A a)-> b.run(){a.run}如果设计前就把A提升到接口,就没必要用这种方法了。不是接口这种改也会改到很多代码。不如字节增强

anti-corruption-layer

AntiCorruptionLayer(Old old)

New(AntiCorruptionLayer)-》if(!antiCorruptionLayer.handle){new.handle}

在新和旧中间隔了一层,当初改活动框架的时候是manager(New, Old)-> if(isNew) {} else

bridge

A -》new B(A a)-> b.walk(){a.run}A B两个是不同的接口,适用于在新的方案里面,包含旧的处理

Extension Objects

对已有的实现类或则抽象类重构可以用到。

Strangler

代码只是核心简单展示了一个过程,但是里面应该很多细节。如下图更合适

卢哥的当初slg项目,创建新的模块2, 抽了了一个新的项目,通过spring注入新的游戏cmd,if(!(new cmd can handle))old cmd handle

网络

ambassador(在游戏中应该很少用到)

每个 client 拥有独立的 ambassador,ambassador去全局寻找合适的服务器。

Server Session

测试

arrange-act-asset(spock given-when-then)

重点还是方法需要无副作用,void方法 只能存在与数据对象

Object Mother

Page Object

org.htmlunit一个框架把页面变成一个对象有助于代码直接测试。

Service Stub(好像没什么用,测试假的类作用是?)

缓存(在游戏开发里面,缓存依赖于玩家数据的设计)

cache

各种内存跟数据库交互同步信息的策略

熔断 (没到这个水平,不知道干嘛)

circuit-breaker

在远程调用中间加一层 断路开关,当多次失败的时候打开断路开关,中断请求。其状态有 断路器开,半开,关。开的时候,中断全部请求。在等待一段时间后改为半开。尝试请求。成功变为关闭,失败变为开启

retry

当方法失败/异常的时候不放弃,sleep一会儿重试。暂未想到合适的业务

性能

Data Locality

高频,性能有瓶颈的地方写需要写最简单的代码

Throttling

分布式

Leader Election

bully(选最大或则最小的id)

ring(轮询)

Microservices Aggregator

全部请求打到一个服务器,让一个服务器分发到其他微服务中

Microservices API Gateway(同上)

Microservices Client-Side UI Composition(同上但是是前端的)

Microservices Distributed Tracing(存疑)

Microservices Idempotent Consumer(唯一id处理幂等性问题)

Microservices Log Aggregation

设计目的把分布式日志打到用一个地方 ELK

SAGA

注意细节,Service A 和 事务异常后调用 Compensate Service 不是同一个类。

Service Locator(结构 -> 分布式)

Service Locator还需要很多细节不同,譬如服务器健康问题,失败回调等等

数据结构与算法

Spatial Partition

十字链表

理念

Tolerant Reader

尽可能的兼容客户端请求过来的业务,就算异常也要有一个明确的返回

相关推荐
花卷HJ2 小时前
Android 多媒体文件工具类封装(MediaFileUtils)
android·java
爱生活的苏苏2 小时前
修改默认滚动条样式
开发语言·javascript·ecmascript
モンキー・D・小菜鸡儿2 小时前
Android 自定义粒子连线动画视图实现:打造炫酷背景效果
android·java
Java天梯之路2 小时前
# Spring Boot 钩子全集实战(四):`SpringApplicationRunListener.environmentPrepared()` 详解
java·spring·面试
i757_w2 小时前
IDEA快捷键被占用
java·ide·intellij-idea
白鸽(二般)2 小时前
Spring 的配置文件没有小绿叶
java·后端·spring
AC赳赳老秦2 小时前
跨境电商决胜之道:基于深度数据分析的选品策略与库存优化
大数据·开发语言·人工智能·python·php·跨境电商·deepseek
zhangkaixuan4562 小时前
Paimon Action Jar 实现机制分析
java·大数据·flink·paimon·datalake
charlie1145141912 小时前
快速备份与恢复 Conda 环境
linux·开发语言·windows·深度学习·机器学习·conda·环境配置