Skip to content

Instantly share code, notes, and snippets.

@chrisza4
Created May 15, 2020 10:25
Show Gist options
  • Select an option

  • Save chrisza4/acd9aa67af3883620edfc299a0322c0a to your computer and use it in GitHub Desktop.

Select an option

Save chrisza4/acd9aa67af3883620edfc299a0322c0a to your computer and use it in GitHub Desktop.
class X {
A(): void {
const x = new Y()
// Message
const message = new Message()
message.metadata = { data: "hello", data2: "world" }
message.callback = () => console.log('Done')
// Message
x.B(message)
}
}
class Y {
async B(message: Message) {
await this.DoSomething(message.metadata)
message.callback()
}
}
class Message {
public metadata: any
public callback: () => void
}
// กรณีนี้เวลา X คุยกับ Y ใน x.B(message) เราเข้าใจ Intention ว่าทำไมต้องรคุยกัน คุยกันเพื่ออะไร และมีขั้นตอนอะไรบ้าง จากการอ่านแค่ X,Y เท่านั้น
// ==========================================================
class X2 {
A(): void {
const x = new Y2()
const message = new VerySmartMessage()
x.B(message)
}
}
class Y2 {
B(message: VerySmartMessage) {
return message.computed()
}
}
class VerySmartMessage {
public computed() {
const subSystem1 = new AnotherClass()
const subSystem2 = new AnotherAnotherClass()
// Do complicated things
}
}
// กรณีนี้จะเห็นว่า เวลาเราอ่าน X2, Y2 คุยกัน แต่คุยกันเพื่ออะไร ต้องการอะไรจากสิ่งนี้ มันไปอยู่ใน VerySmartMessage หมดเลย
// มันทำให้เกิด 3-ways reasoning ที่ต้องเข้าใจ 3 ส่วน
// แล้วถ้าเกิด Logic ที่จำเป็นต่อการคุยกันนี้ ครึ่งนึงอยู่ใน VerySmart ครึ่งนึงอยู่ใน Y2 จะทำความเข้าใจได้ยากมากกกกกก
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment