コンテンツにスキップ

関心の分離

出典: フリー百科事典『ウィキペディア(Wikipedia)』

: separation of concernsSoC




[]


separation of concernsW1974On the role of scientific thoughtDijkstra 1974: 使1989Chris Reade Elements of Functional ProgrammingChris Reade 1989: 

[]


separation of presentation and content

React: /hook/[]


ReactJavaScript(  ) hookSoC

onMemberChangedSoC

2UIconstructorcountUIcomponentDidMountrenderUIcomponentWillUnmount
class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = { countA: 0, countB:0 };
  }

  componentDidMount() {
    this.timerIDa = setInterval(() => this.tickA(), 1000)
    this.timerIDb = setInterval(() => this.tickB(), 1000)
  }

  componentWillUnmount() {
    clearInterval(this.timerIDa);
    clearInterval(this.timerIDb);
  }

  tickA() {
    this.setState({ countA: this.state.countA + 1});
  }
  tickB() {
    this.setState({ countB: this.state.countB + 1});
  }

  render(){
    return <div>now count: A/{this.state.countA} - B/{this.state.countB}</div>
  }
}

1AB Reacthookhookclass interface1hookhookAhook1SoC
function Clock() {
  // Timer A /////////////////////////////////////////
  const [countA, setCountA] = useState(0);
  useEffect(()=>{
    const id = setInterval(() => setCountA(n=>n+1), 1000);
    return ()=> clearInterval(id)
  }, []);
  // Timer A /////////////////////////////////////////

  // Timer B /////////////////////////////////////////
  const [countB, setCountB] = useState(0);
  useEffect(()=>{
    const id = setInterval(() => setCountB(n=>n+1), 1000);
    return ()=> clearInterval(id)
  }, []);
  // Timer B /////////////////////////////////////////

  return <div>now count: A/{countA} - B/{countB}</div>
}


"It can take input from the user and display information, but it should not manipulate the information other than to format it for display." p.96

[]


: Presentation Domain Separation[1][2][3]2[4][5]



PresentationDomain[6]

[7]

UI[8]

[9]

[10]ViewSQLView[11][12]

関連項目[編集]

参考資料[編集]

  • Multi-Dimensional Separation of Concerns
  • TAOSAD
  • Tutorial and Workshop on Aspect-Oriented Programming and Separation of Concerns
  • Chris Reade (1989). Elements of functional programming. International computer science series.. Wokingham, England: Addison-Wesley. ISBN 0201129159. OCLC 19124943 
  • Dijkstra, E.W. (1974). E.W. Dijkstra Archive: On the role of scientific thought (EWD447). http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD447.html. 
  1. ^ a b c d e f g h i j k l Fowler, M. (2001-03). “Separating user interface code”. IEEE Software 18 (2): 96–97. doi:10.1109/52.914754. ISSN 0740-7459. http://ieeexplore.ieee.org/document/914754/. 

脚注[編集]

  1. ^ "Separating User Interface Code" p.96 [g 1]
  2. ^ "separation of presentation and domain" p.97 [g 1]
  3. ^ "refer to the user interface code as presentation code and the other code as domain code." p.96 [g 1]
  4. ^ "Presentation and domain are two separable concerns I’ve found" p.97[g 1]
  5. ^ "The general principle here is that of separating concerns" p.97[g 1]
  6. ^ "A clear separation lets you concentrate on each aspect of the problem separately" p.96 [g 1]
  7. ^ "It also lets different people work on the separate pieces, which is useful when people want to hone more specialized skills." p.96 [g 1]
  8. ^ "Making the domain independent of the presentation also lets you support multiple presentations on the same domain code" p.96 [g 1]
  9. ^ "Separating the domain code makes it much easier to test." p.97 [g 1]
  10. ^ "For a simple set of pages, there is an overhead (although I would call it a small one)" p.97 [g 1]
  11. ^ "the tools don’t provide any place to extract the domain code. If straight updates to data and view are all you do, then this is not a problem. ... However, once domain logic gets complicated, it becomes hard to see how to separate it." p.97 [g 1]
  12. ^ "as the set gets more complicated, the value of the separation grows." p.97 [g 1]