diff --git a/tiddlers/content/_Coursework.tid b/tiddlers/content/_Coursework.tid index ed48289..45c9175 100644 --- a/tiddlers/content/_Coursework.tid +++ b/tiddlers/content/_Coursework.tid @@ -16,6 +16,16 @@ +! Review Exercises +
+<$list filter="[tag[review]tag[toc]!tag[hidden]sort[title]]"> +<$set name="strippedTitle" filter="[all[current]split[/]last[]]"> +<$link><>
+ + +
+ + editor : getText(): author + +' set the author field in the book +editor -> book : setAuthor(author) + +@enduml + + +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +participant "BookEditor" as editor <
> +participant "Book" as book <> + +' get the author from the relevant text component +editor --> editor : getText() : author + +' set the author field in the book +editor -> book : setAuthor(author) + +@enduml +]]] + +!Actors +We can show users interacting with the system using an `actor`: + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "BookEditor" as editor <<form>>
+participant "Book" as book <<domain>>
+
+' user enters book details and clicks the save button
+user -> editor: enters book details
+user -> editor : clicks save button
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+' set the author field in the book
+editor -> book : setAuthor(author)
+
+@enduml
+
+ + +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "BookEditor" as editor <> +participant "Book" as book <> + +' user enters book details and clicks the save book button +user -> editor: enters book details +user -> editor : clicks save button + +' get the author from the relevant text component +editor --> editor : getText() : author + +' set the author field in the book +editor -> book : setAuthor(author) + +@enduml +]]] + +!Activation Bars +Activation bars show when an object is active. This will often be as a result of a method call on the object. Activation bars can be helpful to show where a method call finishes and ends, and generally make the diagram easier to understand: + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "BookEditor" as editor <<form>>
+participant "Book" as book <<domain>>
+
+' user enters book details and clicks the save button
+user -> editor++ : enters book details
+editor--
+
+user -> editor++ : clicks save button
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+' set the author field in the book
+editor -> book++ : setText(author)
+book--
+
+editor--
+@enduml
+
+ +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "BookEditor" as editor <> +participant "Book" as book <> + +' user enters book details and clicks the save book button +user -> editor++ : enters book details +editor-- + +user -> editor++ : clicks save button + +' get the author from the relevant text component +editor --> editor : getText() : author + +' set the author field in the book +editor -> book++ : setAuthor(author) +book-- +editor-- + +@enduml +]]] + +You use `++` and `--` to control the activation bars on an object. + +A `return` will also deactivate an object. + +!Object Construction +We can show an object being created as follows: + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "BookEditor" as editor <<form>>
+participant "Book" as book <<domain>>
+
+' user enters book details and clicks the save book button
+user -> editor++ : enters book details
+editor--
+
+user -> editor++ : clicks save button
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+' construct the book object
+create book
+editor -> book : <<construct>>
+
+' set the author field in the book
+editor -> book++ : setAuthor(author)
+editor--
+@enduml
+
+ +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "BookEditor" as editor <> +participant "Book" as book <> + +' user enters book details and clicks the save book button +user -> editor++ : enters book details +editor-- + +user -> editor++ : clicks save button + +' get the author from the relevant text component +editor --> editor : getText() : author + +create book +editor -> book : <> + +' set the author field in the book +editor -> book++ : setAuthor(author) +book-- +editor-- + +@enduml +]]] + +If we wanted to pass the details into the Book constructor instead of using the set method: + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "BookEditor" as editor <<form>>
+participant "Book" as book <<domain>>
+
+' user enters book details and clicks the save book button
+user -> editor++ : enters book details
+editor--
+
+user -> editor++ : clicks save button
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+create book
+editor -> book : <<construct(author)>>
+
+                      
+                      
+                      
+
+@enduml
+
+ +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "BookEditor" as editor <> + + +' user enters book details and clicks the save book button +user -> editor++ : enters book details +editor-- + +user -> editor++ : clicks save button + +' get the author from the relevant text component +editor --> editor : getText() : author + +create "Book" as book <> +editor -> book : <(author)>> +@enduml +]]] + +! Variables and Construction +We will usually do something with an object when we create it, so we need a variable name for representing the constructed object: + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "BookEditor" as editor <<form>>
+participant "book: Book" as book <<domain>>
+
+' user enters book details and clicks the save book button
+user -> editor++ : enters book details
+editor--
+
+user -> editor++ : clicks save button
+
+create book
+editor -> book : <<construct>>
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+' set the author field in the book
+editor -> book++ : setAuthor(author)
+book--
+
+' create a DAO
+create "BookListDAO" as dao <<DAO>>
+editor -> dao : <<construct>>
+
+' save book
+editor -> dao++ : save(book)
+dao--
+editor--
+@enduml
+
+ + +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "BookEditor" as editor <> +participant "book : Book" as book <> +participant "BookListDAO" as dao <> + +' user enters book details and clicks the save book button +user -> editor++ : enters book details +editor-- + +user -> editor++ : clicks save button + +create book +editor -> book : <> + +' get the author from the relevant text component +editor --> editor : getText() : author + +' set the author field in the book +editor -> book++ : setAuthor(author) +book-- + +' create a DAO +create dao +editor -> dao : <> + +' save book +editor -> dao++ : save(book) +dao-- +editor-- +@enduml +]]] + +!Object Destruction +We sometimes want to show when an object is destroyed, or at least no longer active. This is useful for showing when a form is no longer being displayed on the screen. If you have a main menu that creates other forms in response to the user clicking buttons, then destroying one of those other forms would imply that the user is back at the main menu again, and can longer interact with the destroyed form. + +
@startuml
+' use strict UML mode
+skinparam style strictuml
+
+actor "User" as user
+participant "MainMenu" as menu <>
+participant "BookEditor" as editor <<form>>
+participant "book : Book" as book <<domain>>
+
+'user clicks add new book button
+user -> menu++: click 'Add New Book'
+create editor
+menu -> editor : <<construct>>
+
+' user enters book details and clicks the save book button
+user -> editor++ : enters book details
+editor--
+
+user -> editor++ : clicks save button
+
+create book
+editor -> book : <<construct>>
+
+' get the author from the relevant text component
+editor --> editor : getText() : author
+
+' set the author field in the book
+editor -> book++ : setAuthor(author)
+book--
+
+' create a DAO
+create "BookListDAO" as dao <<DAO>>
+editor -> dao : <<construct>>
+
+' save book
+editor -> dao++ : save(book)
+dao--
+editor--
+
+destroy editor
+
+@enduml
+
+ + +[[plantuml[ +@startuml +' use strict UML mode +skinparam style strictuml + +actor "User" as user +participant "MainMenu" as menu <> +participant "BookEditor" as editor <> +participant "book : Book" as book <> +participant "BookListDAO" as dao <> + +'user clicks add new book button +user -> menu++: click 'Add New Book' +create editor +menu -> editor : <> + +' user enters book details and clicks the save book button +user -> editor++ : enters book details +editor-- + +user -> editor++ : clicks save button + +create book +editor -> book : <> + +' get the author from the relevant text component +editor --> editor : getText() : author + +' set the author field in the book +editor -> book++ : setAuthor(author) +book-- + +' create a DAO +create dao +editor -> dao : <> + +' save book +editor -> dao++ : save(book) +dao-- +editor-- + +destroy editor + +@enduml +]]] + +!Level of Detail +We don't want a one-to-one mapping between diagram elements and source code. That would produce a messy diagram that doesn't help us much. What we are aiming for is to see the most important bits of the system, particularly the interaction between the objects. It is a bit of a balancing act — too much detail results in a diagram that is effectively unreadable, and too little results in a diagram that is not a useful representation of the system. + +We want to show how the classes and methods that appear in the class diagrams are used to complete a particular use case. It is the interactions between the classes and the method calls that we want to see in a sequence diagram. If a programmer is given accurate domain and system model class diagrams, and a sequence diagram for a use case, then there should be just enough detail in the diagram to show the programmer how to use the classes in the class diagrams to implement the use case, and no more detail than that. + +Note: Normally we wouldn't bother showing getter and setter calls like we have in this tutorial. We wanted to keep it simple, and use something that you might have seen before if you have done some basic java programming.