??????Robert%20C.Martin????????(Maintainability)%20???????,??????4?????: - PowerPoint PPT Presentation

About This Presentation
Title:

??????Robert%20C.Martin????????(Maintainability)%20???????,??????4?????:

Description:

– PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 57
Provided by: WangY155
Category:

less

Transcript and Presenter's Notes

Title: ??????Robert%20C.Martin????????(Maintainability)%20???????,??????4?????:


1
  • ????????

2
??????
  • ??????????
  • ??????
  • ????
  • ??????
  • ??????
  • ??????
  • ??????
  • ?????

3
??????????
  • ????????????
  • ??????Robert C.Martin????????(Maintainability)
    ???????,??????4?????
  • ????(Rigidity)
  • ????(Fragility)
  • ????(Immobility)
  • ????(Viscosity)

Robert C.Martin
4
??????????
  • ????????????
  • ?????????Peter Coad??,??????????????????
  • ????(Extensibility)
  • ???(Flexibility)
  • ????(Pluggability)

Peter Coad
5
??????????
  • ????????????
  • ?????(Reuse)?????????,????????????,??????,??????,
    ??????????????????
  • ?????????????????????????
  • ??????????,?????????????????????,???????????????,?
    ????????????????????,????????????

6
??????????
  • ????????????
  • ????????????????????????????,??(Refactoring)??????
    ?????????,??????????????????,????????????????,????
    ?????????

Martin Fowler
7
??????????
  • ??????????
  • ?????????????7?,????????????,??????,?????

?????? ?????? ???
?????? (Single Responsibility Principle, SRP) ???????,?????????????? ?????
???? (Open-Closed Principle, OCP) ???????????,????????,?????? ??????????????? ?????
?????? (Liskov Substitution Principle, LSP) ??????,???????????????????? ????? ?????
?????? (Dependency Inversion Principle, DIP) ????????,?????????? ?????
?????? (Interface Segregation Principle, ISP) ??????????????????? ?????
?????? (Composite Reuse Principle, CRP) ????????????????????,?????? ???????? ?????
????? (Law of Demeter, LoD) ??????????????????,???????? ????????,?????????????????? ?,????????????????? ?????
8
??????
  • ????????
  • ??????(Single Responsibility Principle, SRP)????
  • ??????????????,?????????????????
  • ??????
  • Every object should have a single responsibility,
    and that responsibility should be entirely
    encapsulated by the class.
  • ?????????
  • ??????,???????????????
  • ??????
  • There should never be more than one reason for a
    class to change.

9
??????
  • ????????
  • ???(??????,????)???????,??????????,??????????????,
    ??????????????,??????????,?????????????
  • ?????????????????????,????????????,??????????????
  • ?????????????????????,??????????????????,?????????
    ?????,???????????????????,????????????????????????
    ??????????

10
??????
  • ????????
  • ????
  • ???Java?C/S??????????????(Login)??
  • ????????????????

11
??????
  • ????????
  • ????

12
????
  • ??????
  • ????(Open-Closed Principle, OCP)????
  • ?????????????,????????????????????,???????????????
    ??????,????????????????????????
  • ??????
  • Software entities should be open for extension,
    but closed for modification.

13
????
  • ??????
  • ?????Bertrand Meyer?1988???,??????????????????
  • ?????????,???????????????????????????????????

14
????
  • ??????
  • ????????????
  • ???????????????????????????,????????(Principle
    of Encapsulation of Variation, EVP)???????????????
    ????

15
????
  • ??????
  • ????
  • ???????????????????,????????????????,?????????????
    ?????,??????????
  • ?????????,????????????

16
????
  • ??????
  • ????

17
??????
  • ????????
  • ??????(Liskov Substitution Principle,
    LSP)???????,???????????,?????
  • ?????????S???o1,?????T???o2,???T???????P??????o1??
    ??o2?,??P???????,????S???T?????
  • ??????
  • If for each object o1 of type S there is an
    object o2 of type T such that for all programs P
    defined in terms of T, the behavior of P is
    unchanged when o1 is substituted for o2 then S is
    a subtype of T.
  • ???????????????
  • ??????(??)??????????????????
  • ??????
  • Functions that use pointers or references to base
    classes must be able to use objects of derived
    classes without knowing it.

18
??????
???(Jeannette M. Wing),????????,???.??????,???????
????????????????,ACM?IEEE???
  • ????????
  • ???????2008?????????????????????????????Barbara
    Liskov????.????Jeannette Wing???1994?????????Let
    q(x) be a property provable about objects x of
    type T. Then q(y) should be true for objects y of
    type S where S is a subtype of T.

???????(Barbara Liskov),????????,2008??????,2004?
??.???????,???????,??????????,????????????????????
????????????????????????????
19
??????
  • ????????
  • ???????????????????????????,?????????????????????
    ????,??????????????,???????,??????????????????,???
    ??????????
  • ????????????????????,????????????????????,????????
    ??????????????,?????????????,?????????????

20
??????
  • ????????

???????? ?????? ?
21
??????
  • ????????
  • ????
  • ????????????(?????)?????,??????(DataOperator)?????
    ???????????,?????????????,CipherA?CipherB,????????
    ???,?DataOperator?????????????????????

22
??????
  • ????????
  • ????
  • ?????????????????????????????,??CipherA??CipherB,?
    ???????Client??????DataOperator????,????????
  • ???????????????,??????????,???????

23
??????
  • ????????
  • ????

24
??????
  • ????????
  • ??????(Dependence Inversion Principle, DIP)?????
  • ?????????????,????????????????????,??????????
  • ??????
  • High level modules should not depend upon low
    level modules, both should depend upon
    abstractions. Abstractions should not depend upon
    details, details should depend upon abstractions.
  • ??????
  • ???????,?????????
  • ??????
  • Program to an interface, not an implementation.

25
??????
  • ????????
  • ???????Robert C. Martin?1996??C
    Reporter?????Engineering Notebook????,???????2002
    ????????Agile Software Development, Principles,
    Patterns, and Practices??

26
??????
  • ????????
  • ????,???????????????????,?????????????????????,?
    ??????????
  • ?????????????,?????????????,???????????????????,??
    ????????????????????

27
??????
  • ????????
  • ?????????????????????????,?????????????
  • ???????,????????
  • Put Abstractions in Code, Details in Metadata
  • (?????????????(The Pragmatic programmer from
    journeyman to master) )

28
??????
  • ????????
  • ??????
  • ?????
  • ??????
  • ??????
  • ??????????????????,??????????????????

29
??????
  • ????????
  • ????

30
??????
  • ????????
  • ????
  • ????(Constructor Injection)?????????????
  • ????(Setter Injection)??Setter?????????
  • ????(Interface Injection)?????????????

31
??????
  • ????????
  • ????
  • ?????????????,????????????????????,?????????????(D
    atabaseSource)???????????????(TextSource),????????
    ?XML??(XMLTransformer)?????XLS??(XLSTransformer)??

32
??????
  • ????????
  • ????
  • ???????,??????????????????????,???????????????????
    ?????,???MainClass????????,???????,???????????????
    ??????????

33
??????
  • ????????
  • ????

34
??????
  • ????????
  • ??????(Interface Segregation Principle,
    ISP)?????
  • ??????????????????
  • ??????
  • Clients should not be forced to depend upon
    interfaces that they do not use.
  • ??,??????????????????
  • ?????????
  • ????????,????????????????,???????????????????????
  • ??????
  • Once an interface has gotten too 'fat' it needs
    to be split into smaller and more specific
    interfaces so that any clients of the interface
    will only know about the methods that pertain to
    them.

35
??????
  • ????????
  • ?????????????????,?????????????????????????????,??
    ??,???????,????????
  • (1) ????????????,??????????????,????????????????
    ?
  • (2) ??????????????,??????,??????????????,?????????
    ?????????,???????????

36
??????
  • ????????
  • ?????????????,????????????,????????????????,??????
    ?????,???????????
  • ???????????????????,?????????????????,??????????,?
    ???????????

37
??????
  • ????????
  • ????
  • ?????????????????,??????????????(???)AbstractServi
    ce???????????????????????????

38
??????
  • ????????
  • ????

39
??????
  • ????????
  • ??????(Composite Reuse Principle,
    CRP)?????/??????(Composition/ Aggregate Reuse
    Principle, CARP),?????
  • ????????,??????????????
  • ??????
  • Favor composition of objects over inheritance as
    a reuse mechanism.

40
??????
  • ????????
  • ???????????????????????(???????????)??????????,???
    ???????????????????????????????????????????????/
    ????,?????

41
??????
  • ????????
  • ????????,???????????????????????????,?????/???????
    ???
  • ????????,???????????????????????????,???????????
    ,????????????????????(???? )
  • ??/???????????,????????????????????????(???? )

42
??????
  • ????????
  • ??/???????????,???????????,???????????????????,???
    ???????/??????????????,??????,????????????,??????
    ??????????,?????,????????????????????????????,????
    ?????????

43
??????
  • ????????
  • ????
  • ?????????????????????

44
??????
  • ????????
  • ????
  • ?????????????,?????JDBC?????,????????????,?????DBU
    til???????StudentDAO??JDBC??,??TeacherDAO???????,?
    ????????DBUtil?,???StudentDAO?TeacherDAO????,?????
    ???????,????????,????????
  • ????????????????

45
??????
  • ????????
  • ????

46
?????
  • ???????
  • ?????(Law of Demeter, LoD)?????????(Least
    Knowledge Principle, LKP),????????,??????????
  • (1) ??????????????Don't talk to strangers.
  • (2) ????????????????Talk only to your immediate
    friends.
  • (3) ?????????????????????,????????????????????????
    ??Each unit should have only limited knowledge
    about other units only units "closely" related
    to the current unit.

47
?????
  • ???????
  • ????????1987????????(Northeastern
    University)????Demeter??????
  • ????,???????????????????????????????????,????????,
    ?????????????,???????,??????????????,?????????????
    ???????

48
?????
  • ???????
  • ???????,??????,?????????
  • (1) ??????(this)
  • (2) ??????????????????
  • (3) ?????????
  • (4) ????????????????,?????????????
  • (5) ???????????
  • ??????,???????????,?????????,????????

49
?????
  • ???????
  • ????????????????????????????,???????????????,?????
    ??????????????,????????????????????????,??????????
    ????

50
?????
  • ???????
  • ??????????????????,??????????????????????????,???
    ????????????,???????????????????????,?????????????
    ?????????,?????????????????
  • ????????????????????????????????,????????????????
    ?????????????,?????????????????????,???????????,??
    ?????????????????,???????????????????????????????,
    ?????????,???????????????

51
?????
  • ???????
  • ???????????????????
  • ??????,???????????,?????????,???????,?????????????
    ??,?????????????
  • ????????,??????????????????????????
  • ??????,?????,????????????
  • ?????????,???????????????????

52
?????
  • ???????
  • ????
  • ??????(?Form1?Form2??)??????(?DAO1?DAO2??)????????
    ???,????

53
?????
  • ???????
  • ????

54
????
  • ???????????????,??????????,????????????
  • ????????????????,??????,??????,??????????????????
  • ??????????????,???????????????????
  • ???????????????????,?????,??????????????????????
  • ???????????????????????????,??????????????

55
????
  • ??????????????????,????????????????,?????????
  • ?????????????????????????,????????????????????????
  • ???????????????????,???????
  • ????????????????????????????????

56
END
Thanks!
Write a Comment
User Comments (0)
About PowerShow.com