Presentation is loading. Please wait.

Presentation is loading. Please wait.

Martin Q. Zhao 9/20/2013.  Dao De Jing (Tao-Te Ching) & Lao Zi (Lao Tzu)  Dao of Programing  Building the Virtual World  OOAD Principles in Dao De.

Similar presentations


Presentation on theme: "Martin Q. Zhao 9/20/2013.  Dao De Jing (Tao-Te Ching) & Lao Zi (Lao Tzu)  Dao of Programing  Building the Virtual World  OOAD Principles in Dao De."— Presentation transcript:

1 Martin Q. Zhao 9/20/2013

2  Dao De Jing (Tao-Te Ching) & Lao Zi (Lao Tzu)  Dao of Programing  Building the Virtual World  OOAD Principles in Dao De Jing

3

4

5 The Tao Name, concept Nothingness, emptiness Existence 10,000 things, objects Subtlety Heaven & earth, the world Beginning The Tao that can be expressed in words is not the true and eternal Tao… (Tao:1)

6 M & T Books (December 1990) Info Books (September 1986) Patrick Burns (December 16, 2012) Addison-Wesley Professional; 1 edition (July 22, 2004) Hayden Books; 2 Pap/Dskt edition (July 1994)

7  The discipline of computing is …  Computer programs: sets of instructions written in programming languages that automate Real World information transformation processes  Develop a software system is like building a “Virtual World” the systematic study of algorithmic processes that describe and transform information: their theory, analysis, design, efficiency, implementation, and application. The fundamental question underlying all of computing is, ‘What can be (efficiently) automated?’

8  Software systems can be boiled down to  Systems: the solution as a whole (virtual worlds)  Programs: organizational units of code (or the VW)  Procedures: sequences of instructions as a unit  Statements: instructions  Expressions: meaningful combo of tokens  Tokens: variables, constants, operators, punctuations

9  Procedural approach, aka Structured Programming ( mid-1960’s )  OO approach ( since 1980’s )  Data and algorithms go together (in an object)  No “top” unit Data Procedures Or ways to process data top

10  Real World (aka Problem Domain)  Consists of objects (or entities)  Virtual World (aka Solution Domain)  Specs of classes  Objects created at runtime (when VW is alive) Name Address Payment method Brand Category Price Employee ID Name Phone

11  Now let’s focus on the Virtual World  Building the VW involves defining the classes that will be used to create objects at runtime 有物混成,先天地生。 寂兮寥兮,独立而不改。 周行而不殆,可以为天地母。 吾不知其名,强字之为道 , 强为之名曰大 。 There is a thing integratedly formed And born earlier than Heaven and Earth. Silent and empty, it relies on nothing, Moving around forever. We may regard it as the mother of all things I don’t know its name, so I name it as Tao, And further name it as Great. (Tao:25) Object(s) S/W System- VW

12  What is the simplest Java class?  Can it be used to create any object?  But can this object be used?  What happens behind the scene?  Class Object is the “mother” of all Java classes class A {}class Dummy {} class DummyTest { public static void main (String[] x) { Dummy d = new Dummy(); } System.out.println(d); Add it here extends Object Add it here Inheritance

13  An object has a type  Object : instance of a class, created at runtime  Class : template of all objects of the same type  An object has an identity  Two labs in CSB may look the same, but each is a unique entity  (Classes of) objects have their responsibilities: they need to  Know some information  perform some operations o:Order -orderId=101 -orderDate=1/1/11 +calOrderTotal() … Abstraction

14  One easy choice  Just use one GOD CLASS, which  Knows everything and can do everything  But that is not OO, which tends to  Partition system into many classes around RW concepts, and  Distribute intelligence/behavior evenly among them 天地不仁,以万物为刍狗 … Heaven and Earth have no favorite, They deem all objects as equally common. (Tao:5) R. Martin (2003) Prentice Hall UML for Java Programmers

15  Keep being simple in nature and mind ( 见素抱 朴 )  close to Tao  to avoid “an early end” ( 不道早已 :whatever goes against Tao will come to an early end )  Keeping classes’ responsibilities simple (or cohesive), helps reuse & improve system maintainability 五色令人目盲; 五音令人耳聋; 五味令人口爽; 驰聘畋猎,令人心发狂; 难得之货,令人行妨。 The five colors make man blind; The five sounds make man deaf; The five tastes make man lose his sense of taste; Riding and hunting make man wild w/ excitement; Rare goods goad man into stealing... (Tao:12)

16  Instead of using all-purpose objects, objects with a single responsibility are preferred R. Martin (2002) Prentice Hall Agile Software Development Maintainability

17  Focus on the three types of objects 道生一, 一生二, 二生三, 三生万物。 Tao begets the One; The One consists of Two in opposition (the Yin and Yang); The two begets the Three; All things connote the Yin and Yang. (Te:42) Tao begets the One; The One begets the Two; The Two begets the Three; The Three begets 10,000 things. (Te:42) (Cont’d on next slide)

18 Customer SalesRep CustomerForm SalesRepForm OrderFulfillControl OrderControl CustomerEntity OrderEntity ProductEntity System Boundary Actors

19 Entity classes usually represent a domain-specific situation or RW object Need to be saved between sessions Control classes represent a workflow, control, or calculation process Boundary classes are used to model interaction between the system and its actors. Jacobson, Booch, & Rambaugh (1999) Addison-Wesley The Unified Software Development Process

20  Each object can do only one thing  To fulfill its responsibility, an object can ask for help from (aka collaborate with) another object  Object collaboration is done by message passing  A message has  A recipient  An operation requested  Additional information to carry out the operation changeGears(5) me:Rider myBike:Bike Java online tutorials: What Is an Object? http://docs.oracle.com/javase/tutorial/java/concepts/object.html

21 Delegation objectA objectB client  One way to get help is to delegate  The client object will “do nothing” ( 无为 ) itself  It delegates reuses the service from the “server” object that implements it  The client and server roles are specific for each episode server client (Take) no action Choose to (take) no action

22  The Design by Contract approach prescribes  software designers should define formal, precise and verifiable interface specifications for software components (i.e. classes), including  Services/operations to provide, and  For each operation, to specify  Preconditions: need to be true before it’s carried out; Preconditions  Postconditions: need to be true after it’s completed, and Postconditions  Invariants: need to hold true during the object’s life time Invariants  These specifications are referred to as "contracts". Encapsulation Mitchell & McKim (2002) Addison-Wesley Design by Contract, by example

23 Thirty spokes share one hub. It is just the space (the Nothingness) between them that makes a cart function as a cart. (Tao:11)

24 Reusability  An abstract class may have some operations not implemented (in another word, left empty)  An interface is a purely abstract class in which no operations may be implemented  Interfaces and abstract classes are commonly used in design patterns [A design] pattern describes a problem that occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. Alexander, Christopher (1977) Oxford University Press. A Pattern Language: Towns, Buildings, Construction.

25

26

27 Composite pattern Client

28

29 Façade pattern Client

30 Abs. Factory pattern

31 E1T1TankFactory +createTank():E1T1Tank +createShell():E1T1TankShell E1T1Tank E1T1TankShell

32 Command pattern A hook method in the Java AWT API > KeyListener +keyPressed(e:KeyEvent) +keyReleased(e:KeyEvent) +keyTyped(e:KeyEvent) KeyHandler +keyPressed(e:KeyEvent) +keyReleased(e:KeyEvent) +keyTyped(e:KeyEvent) AbstractTank MyGamePanel MyGameFrame

33  Another way to reuse is to use frameworks  A framework provides collections of interfaces, abstract classes, and concrete classes  Sample frameworks in Java  Swing, AWT: from GUI (boundary objects)  JDBC/IO/NIO: for saving entity objects to DB or files  Collections: for managing entity objects

34 天下之至柔,驰骋天下之至坚。 The most supple in the world, Can go through the hardest in the world. (Te:43) The perfect goodness is like water. (Tao:8) 天下莫柔弱于水,而攻坚强者莫 之能胜,以其无以易之。 Nothing in the world is more supple than water, Yet nothing is more powerful than water In attacking hard and strong. (Te:78)

35  Favor flexibility over rigidity 人之生也柔弱,其死也坚强。 万物草木之生也柔脆,其死也枯槁。 故坚强者死之徒,柔弱者生之徒。 …… 强大处下,柔弱处上。 While alive, a person’s body is supple; when dead, it becomes rigid. While alive, grass and trees are supple; when dead, they become dry and stiff. Thus the hard and strong is of the dying sort; the supple and weak is of the living sort. … … Thus the strong and big is inferior to the weak and supple. (Te:76)

36  Rigidity  Fragility  Immobility  Viscosity  Needless complexity  Needless repetition  Opacity R. Martin (2003) Prentice Hall UML for Java Programmers

37

38


Download ppt "Martin Q. Zhao 9/20/2013.  Dao De Jing (Tao-Te Ching) & Lao Zi (Lao Tzu)  Dao of Programing  Building the Virtual World  OOAD Principles in Dao De."

Similar presentations


Ads by Google