Skip to content

Commit

Permalink
docs: init blog selecium
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 11, 2023
1 parent 0083cdb commit a13dc47
Showing 1 changed file with 327 additions and 0 deletions.
327 changes: 327 additions & 0 deletions chatgpt/design-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,330 @@

以上是一些可能需要考虑的问题,你可以根据具体的情况自行扩展或缩减。在与 ChatGPT 进行交流时,你可以使用自然语言来表达你的需求和问题,ChatGPT 将会根据你提供的信息和背景知识来给出相应的建议和解决方案。同时,你也可以通过与 ChatGPT 进行对话来进一步深入探讨和规划软件系统的设计和开发。


# Q2

Q1: 帮我设计一个 JSON Schema 来表达一个系统的软件设计
Q2: 帮我设计一个 Yaml 来表达一个系统的软件设计
Q3: 帮我设计一个 Yaml 来表示一个系统的处理流程
Q4: 帮我设计一个 DSL 来表示一个系统的处理流程
Q5: 在你刚设计的 DSL 里,整合编程相关的要素,诸如于 "Class={}",并重新设计:

```javascript
process MyProcess {
description = "A process for handling customer orders"

step "Receive Order" {
description = "Receives an order from the customer"
type = "manual"
owner = "Customer Service"
}

step "Check Inventory" {
description = "Checks if there is sufficient inventory to fulfill the order"
type = "automated"
owner = "Inventory Management"
depends_on = ["Receive Order"]
}

step "Process Payment" {
description = "Processes payment for the order"
type = "automated"
owner = "Payment Gateway"
depends_on = ["Receive Order", "Check Inventory"]
}

step "Fulfill Order" {
description = "Fulfills the order and ships it to the customer"
type = "automated"
owner = "Warehouse Management"
depends_on = ["Receive Order", "Check Inventory", "Process Payment"]
}
}
```


帮我设计一个 DSL 来表示一个系统的处理流程,要求:

1. 使用领域驱动设计的思考。
2. 包含编程相关的元素,如类、包、方法等。

只返回这个 DSL,并在 DSL 中添加 注释


```javascript
//定义一个处理流程,包含多个步骤
Process {
name: String, //流程名称
steps: List[Step], //步骤列表
entryPoint: Step //入口步骤
}

//定义一个步骤,包含输入输出和执行代码
Step {
name: String, //步骤名称
inputs: List[Input], //输入列表
outputs: List[Output], //输出列表
code: Code //执行代码
}

//定义一个输入,包含名称和数据类型
Input {
name: String, //输入名称
dataType: DataType //数据类型
}

//定义一个输出,包含名称和数据类型
Output {
name: String, //输出名称
dataType: DataType //数据类型
}

//定义执行代码的接口
Code {
execute: (inputs: Map[String, Any]) => Map[String, Any] //执行代码的方法,输入和输出均为键值对
}

//定义数据类型,包括基本类型和自定义类型
DataType {
String,
Int,
Double,
Boolean,
CustomType(name: String) //自定义类型
}

//示例代码:创建一个处理流程,并添加两个步骤
val process = Process(
name = "My Process",
steps = List(
Step(
name = "Step 1",
inputs = List(
Input("input1", DataType.String),
Input("input2", DataType.Int)
),
outputs = List(
Output("output1", DataType.Double)
),
code = MyCode1()
),
Step(
name = "Step 2",
inputs = List(
Input("input3", DataType.CustomType("MyType")),
Input("input4", DataType.Boolean)
),
outputs = List(
Output("output2", DataType.String),
Output("output3", DataType.Int)
),
code = MyCode2()
)
),
entryPoint = Step1
)

//示例代码:自定义执行代码的实现
class MyCode1 extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val input1 = inputs("input1").asInstanceOf[String]
val input2 = inputs("input2").asInstanceOf[Int]
val result = input1.length.toDouble * input2
Map("output1" -> result)
}
}

class MyCode2 extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val input3 = inputs("input3").asInstanceOf[MyType]
val input4 = inputs("input4").asInstanceOf[Boolean]
val output2 = if (input4) input3.name else ""
val output3 = if (input4) input3.id else 0
Map("output2" -> output2, "output3" -> output3)
}
}
```

现在用上面的 DSL 来表示如何使用一个博客系统的使用

```javascript
//定义用户实体,包含姓名、邮箱和密码
Entity User {
name: String,
email: String,
password: String
}

//定义博客实体,包含标题、内容和作者
Entity Blog {
title: String,
content: String,
author: User
}

//定义评论实体,包含内容和评论者
Entity Comment {
content: String,
author: User
}

//定义处理流程
Process {
name: "Blog System",
steps: List(
Step(
name: "Register",
inputs: List(
Input("name", DataType.String),
Input("email", DataType.String),
Input("password", DataType.String)
),
outputs: List(
Output("user", DataType.CustomType("User"))
),
code: RegisterCode()
),
Step(
name: "Login",
inputs: List(
Input("email", DataType.String),
Input("password", DataType.String)
),
outputs: List(
Output("user", DataType.CustomType("User"))
),
code: LoginCode()
),
Step(
name: "Create Blog",
inputs: List(
Input("title", DataType.String),
Input("content", DataType.String),
Input("author", DataType.CustomType("User"))
),
outputs: List(
Output("blog", DataType.CustomType("Blog"))
),
code: CreateBlogCode()
),
Step(
name: "Edit Blog",
inputs: List(
Input("blog", DataType.CustomType("Blog")),
Input("title", DataType.String),
Input("content", DataType.String),
Input("author", DataType.CustomType("User"))
),
outputs: List(
Output("blog", DataType.CustomType("Blog"))
),
code: EditBlogCode()
),
Step(
name: "Delete Blog",
inputs: List(
Input("blog", DataType.CustomType("Blog")),
Input("author", DataType.CustomType("User"))
),
outputs: List()
code: DeleteBlogCode()
),
Step(
name: "Comment Blog",
inputs: List(
Input("blog", DataType.CustomType("Blog")),
Input("content", DataType.String),
Input("author", DataType.CustomType("User"))
),
outputs: List(
Output("comment", DataType.CustomType("Comment"))
),
code: CommentBlogCode()
)
),
entryPoint: Register
}

//自定义执行代码
class RegisterCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val name = inputs("name").asInstanceOf[String]
val email = inputs("email").asInstanceOf[String]
val password = inputs("password").asInstanceOf[String]
val user = User(name, email, password)
Map("user" -> user)
}
}

class LoginCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val email = inputs("email").asInstanceOf[String]
val password = inputs("password").asInstanceOf[String]
//根据邮箱和密码查找用户
val user = findUserByEmailAndPassword(email, password)
Map("user" -> user)
}
}

class CreateBlogCode extends
class CreateBlogCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val title = inputs("title").asInstanceOf[String]
val content = inputs("content").asInstanceOf[String]
val author = inputs("author").asInstanceOf[User]
val blog = Blog(title, content, author)
Map("blog" -> blog)
}
}

class EditBlogCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val blog = inputs("blog").asInstanceOf[Blog]
val title = inputs("title").asInstanceOf[String]
val content = inputs("content").asInstanceOf[String]
val author = inputs("author").asInstanceOf[User]
//检查博客是否属于该用户
if (blog.author == author) {
val editedBlog = Blog(title, content, author)
Map("blog" -> editedBlog)
} else {
throw new Exception("You do not have permission to edit this blog.")
}
}
}

class DeleteBlogCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val blog = inputs("blog").asInstanceOf[Blog]
val author = inputs("author").asInstanceOf[User]
//检查博客是否属于该用户
if (blog.author == author) {
//删除博客
deleteBlog(blog)
Map()
} else {
throw new Exception("You do not have permission to delete this blog.")
}
}
}

class CommentBlogCode extends Code {
override def execute(inputs: Map[String, Any]): Map[String, Any] = {
val blog = inputs("blog").asInstanceOf[Blog]
val content = inputs("content").asInstanceOf[String]
val author = inputs("author").asInstanceOf[User]
val comment = Comment(content, author)
//添加评论到博客
addCommentToBlog(blog, comment)
Map("comment" -> comment)
}
}
```

上面的DSL定义了博客系统的处理流程,包含了博客系统中的实体、处理流程的步骤和每个步骤的输入、输出以及执行代码。使用该DSL可以方便地理解博客系统的处理流程,并且可以根据需要进行定制化开发。





0 comments on commit a13dc47

Please sign in to comment.