Commit 8e4c0903 authored by Nathan Bean's avatar Nathan Bean
Browse files

Updated to new theme

parent 4bd22bfb
......@@ -2,3 +2,5 @@
# Generated files at default location
/public/
/resources/_gen
.hugo-build.lock
\ No newline at end of file
[submodule "themes/ksucs-hugo-theme"]
path = themes/ksucs-hugo-theme
url = https://github.com/russfeld/ksucs-hugo-theme.git
[submodule "themes/hugo-theme-relearn"]
path = themes/hugo-theme-relearn
url = https://github.com/ksu-cs-textbooks/hugo-theme-relearn.git
baseURL = "https://textbooks.cs.ksu.edu/cis400"
languageCode = "en-us"
title = "K-State CIS 400 Textbook"
# Change the default theme to be use when building the site with Hugo
theme = "ksucs-hugo-theme"
# For search functionality
[outputs]
home = [ "HTML", "RSS", "JSON"]
page = [ "HTML", "Iframeable", "Teleprompter"]
section = [ "HTML", "Iframeable", "Teleprompter"]
[params]
landingPageURL = "/cis400"
projectName = "The Flying Saucer"
projectUpstream = "https://github.com/ksu-cis/flying-saucer.git"
textbookURL = "https://textbooks.cs.ksu.edu/cis400"
editURL = "https://gitlab.cs.ksu.edu/nhbean/cis400-textbook/tree/master/content/"
description = "K-State CIS 400 Textbook"
author = "Nathan H. Bean"
showVisitedLinks = false
themeVariant = "purple"
disableLanguageSwitchingButton = true
linenumbers = true
[blackfriday]
plainIDAnchors = true
hrefTargetBlank = true
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
# Custom output format for iframes
[outputFormats]
[outputFormats.Iframeable]
name = "Iframeable"
baseName = "embed"
mediaType = "text/html"
isPlainText = false
isHTML = true
[outputFormats.Teleprompter]
name = "Teleprompter"
baseName = "tele"
mediaType = "text/html"
isPlainText = false
isHtml = true
baseURL = "https://textbooks.cs.ksu.edu/cis400"
languageCode = "en-us"
title = "K-State CIS 400 Textbook"
canonifyURLs = true
enableGitInfo = true
# Change the default theme to be use when building the site with Hugo
theme = "ksucs-hugo-theme"
theme = ["hugo-theme-relearn"]
# For search functionality
[outputs]
home = [ "HTML", "RSS", "JSON"]
page = [ "HTML", "Iframeable", "Teleprompter"]
section = [ "HTML", "Iframeable", "Teleprompter"]
home = ["HTML", "RSS", "PRINT", "JSON"]
section = ["HTML", "RSS", "PRINT", "TELE", "EMBED"]
page = ["HTML", "RSS", "PRINT", "TELE", "EMBED"]
[params]
landingPageURL = "/cis400"
projectName = "The Flying Saucer"
projectUpstream = "https://github.com/ksu-cis/flying-saucer.git"
alwaysopen = false
textbookURL = "https://textbooks.cs.ksu.edu/cis400"
editURL = "https://gitlab.cs.ksu.edu/nhbean/cis400-textbook/tree/master/content/"
description = "K-State CIS 400 Textbook"
author = "Nathan H. Bean"
editURL = "https://gitlab.cs.ksu.edu/nhbean/ksucs-hugo/tree/master/cis400-textbook/"
author = "Nathan Bean"
description = "K-State CIS 642/643 Textbook"
showVisitedLinks = false
themeVariant = "purple"
disableLanguageSwitchingButton = true
disableSearch = false
disableSeoHiddenPages = true
disableTagHiddenPages = true
disableAssetBusting = true
disableInlineCopyToClipboard = true
disableShortcutsTitle = false
disableLandingPageButton = true
disableLanguageSwitchingButton = false
disableBreadcrumbs = false
disableToc = false
disableMathJax = true
disableMermaid = true
disableSwagger = true
disableNextPrev = false
themeVariant = ["light-theme", "dark-theme"]
collapsibleMenu = true
additionalContentLanguage = ["en"]
#landingPageURL = "/cis642-643"
#textbookURL = "https://textbooks.cs.ksu.edu/cis642-643"
linenumbers = true
[blackfriday]
......@@ -29,21 +48,12 @@ section = [ "HTML", "Iframeable", "Teleprompter"]
hrefTargetBlank = true
[markup]
[markup.highlight]
# if set to `guessSyntax = true`, there will be no unstyled code even if no language
# was given BUT mermaid code fences will not work anymore! So this is a mandatory
# setting for your site
guessSyntax = false
style = "monokai"
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
# Custom output format for iframes
[outputFormats]
[outputFormats.Iframeable]
name = "Iframeable"
baseName = "embed"
mediaType = "text/html"
isPlainText = false
isHTML = true
[outputFormats.Teleprompter]
name = "Teleprompter"
baseName = "tele"
mediaType = "text/html"
isPlainText = false
isHtml = true
......@@ -18,4 +18,4 @@ This textbook was authored for the **CIS 400 - Object-Oriented Design, Implement
## Welcome Message
Hello students, and welcome to CIS 400 - Object-Oriented Design, Implementation, and Testing. My name is Nathan Bean, and I will be your instructor for this course.
![Nathan Bean]({{<static "images/bean-bridge.jpg">}})
\ No newline at end of file
![Nathan Bean](/images/bean-bridge.jpg)
\ No newline at end of file
......@@ -34,4 +34,4 @@ The Visual Studio Community Edition is also available as a free download [here](
Discord can be used through its web app at [https://discord.com/webapp](https://discord.com/webapp) or you can [download a native app](https://discord.com/download) for Windows, Linux, Mac, iOS, or Android devices.
## Xamarin Workbooks
Xamarin Workbooks is a note-taking app with built-in C# processing (similar to the Jupyter notebooks you used in CIS 115). You can download the installer directly from GitHub: {{<link "https://github.com/microsoft/workbooks">}}, and scroll down to the Resources section of the README - there's a link to "Download latest public release for Windows".
\ No newline at end of file
Xamarin Workbooks is a note-taking app with built-in C# processing (similar to the Jupyter notebooks you used in CIS 115). You can download the installer [directly from GitHub](https://github.com/microsoft/workbooks), and scroll down to the Resources section of the README - there's a link to "Download latest public release for Windows".
\ No newline at end of file
......@@ -70,7 +70,7 @@ _Edsger Dijkstra, The Humble Programmer (EWD340), Communications of the ACM_
Coupled with this rising demand for programs was a demand for skilled software developers, as reflected in the following table of graduation rates in programming-centric degrees (the dashed line represents the growth of _all_ bachelor degrees, not just computer-related ones):
![Annual Computer-Related Bachelor Degrees Awarded in the US]({{<static "images/1.1.2.1.png">}})
![Annual Computer-Related Bachelor Degrees Awarded in the US](/images/1.1.2.1.png)
Unfortunately, this graduation rate often lagged far behind the demand for skilled graduates, and was marked by several periods of intense growth (the period from 1965 to 1985, 1995-2003, and the current surge beginning around 2010). During these surges, it was not uncommon to see students hired directly into the industry after only a course or two of learning programming (coding boot camps are a modern equivalent of this trend).
......
......@@ -7,7 +7,7 @@ date: 2018-08-24T10:53:26-05:00
The module-based encapsulation suggested by Parnas and his contemporaries grouped state and behavior together into smaller, self-contained units. Alan Kay and his co-developers took this concept a step farther. Alan Kay was heavily influenced by ideas from biology, and saw this encapsulation in similar terms to _cells_.
![Typical Animal Cell]({{<static "images/1.1.5.1.png">}})
![Typical Animal Cell](/images/1.1.5.1.png)
Biological cells are also encapsulated - the complex structures of the cell and the functions they perform are all within a cell wall. This wall is only bridged in carefully-controlled ways, i.e. cellular pumps that move resources into the cell and waste out. While single-celled organisms do exist, far more complex forms of life are made possible by many similar cells working together.
......
......@@ -46,7 +46,7 @@ public class Planet {
It describes a planet as having a mass and a radius. But a class does more than just labeling the properties and fields and providing methods to mutate the state they contain. It also specifies how *memory needs to be allocated* to hold those values as the program runs. In memory, we would need to hold _both_ the mass and radius values. These are stored side-by-side, as a series of bits that are on or off. You probably remember from CIS 115 that a `double` is stored as a **sign bit**, **mantissa** and **exponent**. This is also the case here - a C# `double` requires 64 bits to hold these three parts, and we can represent it with a memory diagram:
![The Planet memory diagram]({{<static "images/1.1.7.1.png">}})
![The Planet memory diagram](/images/1.1.7.1.png)
We can create a specific planet by invoking its constructor, i.e.:
......@@ -56,7 +56,7 @@ new Planet(1, 1);
This *allocates* (sets aside) the memory to hold the planet, and populates the mass and radius with the supplied values. We can represent this with a memory diagram:
![The constructed planet's memory diagram]({{<static "images/1.1.7.2.png">}})
![The constructed planet's memory diagram](/images/1.1.7.2.png)
With memory diagrams, we typically write the values of variables in their human-readable form. Technically the values we are storing are in binary, and would each be `0000000000010000000000000000000000000000000000000000000000000001`, so our overall object would be the bits: `00000000000100000000000000000000000000000000000000000000000000010000000000010000000000000000000000000000000000000000000000000001`.
......@@ -70,7 +70,7 @@ Planet earth = new Planet(1, 1);
Unlike our `double` and other primitive values, this allocated memory holds a _reference_ (an starting address of the memory where the object was allocated). We indicate this with a box and arrow connecting the variable and object in our memory diagram:
![The memory diagram for the earth variable]({{<static "images/1.1.7.3.png">}})
![The memory diagram for the earth variable](/images/1.1.7.3.png)
A reference is either 32 bits (on a computer with a 32-bit CPU) or 64 bits (on a computer with a 64-bit CPU), and essentially is an offset from the memory address $0$ indicating where the object will be located in memory (in the computer's RAM). You'll see this in far more detail in **CIS 450 - Computer Architecture and Operations**, but the important idea for now is the variable stores _where the object is located in memory_ **not** _the object's data itself_. This is also why if we define a class variable but don't assign it an object, i.e.:
......@@ -78,7 +78,7 @@ A reference is either 32 bits (on a computer with a 32-bit CPU) or 64 bits (on a
Planet mars;
```
![The memory diagram for the mars variable]({{<static "images/1.1.7.4.png">}})
![The memory diagram for the mars variable](/images/1.1.7.4.png)
The value of this variable will be `null`. It's because it doesn't point anywhere!
......@@ -88,7 +88,7 @@ Returning to our Earth example, `earth` is an *instance* of the class `Planet`.
Planet mars = new Planet(0.107, 0.53);
```
![The memory diagram for the initialized mars variable]({{<static "images/1.1.7.5.png">}})
![The memory diagram for the initialized mars variable](/images/1.1.7.5.png)
We can even create a **Planet** instance to represent one of the exoplanets discovered by [NASA’s TESS](https://www.nasa.gov/tess-transiting-exoplanet-survey-satellite "Testing Exoplanet Survey Satellite"):
......@@ -96,7 +96,7 @@ We can even create a **Planet** instance to represent one of the exoplanets disc
Planet hd21749b = new Planet(23.20, 2.836);
```
![The memory diagram for three planets]({{<static "images/1.1.7.6.png">}})
![The memory diagram for three planets](/images/1.1.7.6.png)
Let’s think more deeply about the idea of a class as a blueprint. A blueprint for what, exactly? For one thing, it serves to describe the *state* of the object, and helps us label that state. If we were to check our variable **mars’** radius, we do so based on the property **Radius** defined in our class:
......
......@@ -7,9 +7,9 @@ date: 2018-08-24T10:53:26-05:00
If we think back to the concept of _message passing_ in object-oriented languages, it can be useful to think of the collection of public methods available in a class as an _interface_, i.e., a list of messages you can dispatch to an object created from that class. When you were first learning a language (and probably even now), you find yourself referring to these kinds of lists, either in the language documentation, or via Intellisense in Visual Studio.
![The Java API]({{<static "images/2.1.3.1.png">}})
![The Java API](/images/2.1.3.1.png)
![Visual Studio Intellisense]({{<static "images/2.1.3.2.png">}})
![Visual Studio Intellisense](/images/2.1.3.2.png)
Essentially, programmers use these 'interfaces' to determine what methods can be invoked on an object. In other words, which _messages_ can be _passed_ to the object. This 'interface' (note the lowercase i) is determined by the class definition, specifically what methods it contains.
......
......@@ -27,7 +27,7 @@ While a staple of the Unix/Linux filesystem, there was no equivalent to man page
However, once software began to be written with graphical user interfaces (GUIs), it became commonplace to incorporate the user documentation directly into the GUI, usually under a "Help" menu. This served a similar purpose to man pages of ensuring user documentation was always available with the software. Of course, one of the core goals of software design is to make the software so intuitive that users don't need to reference the documentation. It is equally clear that developers often fall short of that mark, as there is a thriving market for books to teach certain software.
![Example Software Books]({{<static "images/2.2.1.png">}})
![Example Software Books](/images/2.2.1.png)
Not to mention the thousands of YouTube channels devoted to teaching specific programs!
......
......@@ -11,7 +11,7 @@ Historically, the test plan was often developed at the same time as the design f
This model of software development has often been referred to as the 'waterfall model' as each task depends on the one before it:
![The Waterfall Model of Software Development]({{<static "images/1.4.2.1.png">}})
![The Waterfall Model of Software Development](/images/1.4.2.1.png)
Unfortunately, as this model is often implemented, the programmers responsible for writing the software are reassigned to other projects as the software moves into the testing phase. Rather than employ valuable programmers as testers, most companies will hire less expensive workers to carry out the testing. So either a skeleton crew of programmers is left to fix any errors that are found during the tests, or these are passed back to programmers already deeply involved in a new project.
......@@ -19,7 +19,7 @@ The costs involved in fixing software errors also grow larger the longer the err
[^nasa2004]: Jonette M. Stecklein, Jim Dabney, Brandon Dick, Bill Haskins, Randy Lovell, and Gregory Maroney. ["Error Cost Escalation Through the Project Life Cycle"](https://ntrs.nasa.gov/citations/20100036670), NASA, June 19, 2014.
![Comparison of System Cost Factors Excluding Operations]({{<static "images/1.4.2.2.png">}})
![Comparison of System Cost Factors Excluding Operations](/images/1.4.2.2.png")
It is clear from the graph and the paper that the cost to fix a software error grows exponentially if the fix is delayed. You probably have instances in your own experience that also speak to this - have you ever had a bug in a program you didn't realize was there until your project was nearly complete? How hard was it to fix, compared to a error you found and fixed right away?
......
......@@ -15,18 +15,18 @@ As with other aspects of the .NET framework, the tools can be used at either the
When building tests with Visual Studio, you will typically begin by adding an xUnit Test Project to your existing solution. Using the wizard will automatically incorporate the necessary Nuget packages into the project. However, you will need to add the project to be tested to the Dependencies list of the test project to give it access to the assembly to be tested. You do this by right-clicking the 'Dependencies' entry under the Test Project in Visual Studio, choosing "Add Project Reference", and in the dialog that pops up, checking the checkbox next to the name of the project you are testing:
![Adding the project reference]({{<static "images/1.4.6.1.gif">}})
![Adding the project reference](/images/1.4.6.1.gif)
To explore and run your tests, you can open the [Test Explorer](https://docs.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer?view=vs-2019) from the "Test" menu. If no tests appear, you may need to build the test project. This can be done by right-clicking the test project in the Solution Explorer and selecting "Build", or by clicking the "Run All" button in the Test Explorer. The "Run All" button will run every test in the suite. Alternatively, you can run individual tests by clicking on them, and clicking the "Run" button.
![Run and Run All buttons]({{<static "images/1.4.6.2.png">}})
![Run and Run All buttons](/images/1.4.6.2.png)
As tests complete, the will report their status - pass or fail - indicated by a green checkmark or red x next to the test name, as well as the time it took to run the test. There will also be a summary available with details about any failures that can be accessed by clicking the test name.
![Test Detail Summary]({{<static "images/1.4.6.3.png">}})
![Test Detail Summary](/images/1.4.6.3.png)
Occasionally, your tests may not seem to finish, but get stuck running. If this happens, check the output panel, switching it from "build" to "tests". Most likely your test process crashed because of an error in your test code, and the output reporting that error will be reported there.
![Test Output in the Output Panel]({{<static "images/1.4.6.4.png">}})
![Test Output in the Output Panel](/images/1.4.6.4.png)
It is a good idea to run tests you've written previously as you add to or refactor your code. This practice is known as _regression testing_, and can help you identify errors your changes introduce that break what had previously been working code. This is also one of the strongest arguments for writing test code rather than performing ad-hoc testing; automated tests are easy to repeat.
\ No newline at end of file
......@@ -9,11 +9,11 @@ The term _test code coverage_ refers to how much of your program's code is execu
Much like Visual Studio provides a Test Explorer for running tests, it provides support for analyzing test coverage. We can access this from the "Test" menu, where we select the "Analyze Code Coverage for All Tests".
![Code coverage command in the Test Menu]({{<static "images/1.4.7.1.png">}})
![Code coverage command in the Test Menu](/images/1.4.7.1.png)
This will build and run all our tests, and as they run it will collect data about how many blocks of code are or are not executed. The results appear in the Code Coverage Results panel:
![Code Coverage results panel]({{<static "images/1.4.7.2.png">}})
![Code Coverage results panel](/images/1.4.7.2.png)
Be aware that there will always be some blocks that are not picked up in this analysis, so it is typical to shoot for a high percentage.
......
......@@ -7,8 +7,8 @@ date: 2018-08-24T10:53:26-05:00
UML class diagrams are largely composed of _boxes_ - basically a rectangular border containing text. UML class diagrams use boxes to represent units of code - i.e. classes, structs, and enumerations. These boxes are broken into compartments. For example, an `Enum` is broken into two compartments:
![A UML Enum representation]({{<static "images/5.3.1.png">}})
![A UML Enum representation](/images/5.3.1.png)
### Stereotypes
UML is intended to be language-agnostic. But we often find ourselves in situations where we want to convey language-specific ideas, and the UML specification leaves room for this with _stereotypes_. Stereotypes consist of text enclosed in double less than and greater than symbols. In the example above, we indicate the box represents an enumeration with the $\texttt{<<enum>>}$ stereotype.
UML is intended to be language-agnostic. But we often find ourselves in situations where we want to convey language-specific ideas, and the UML specification leaves room for this with _stereotypes_. Stereotypes consist of text enclosed in double less than and greater than symbols. In the example above, we indicate the box represents an enumeration with the {{<math>}}$ \texttt{&lt&ltenum&gt;&gt;}${{</math>}} stereotype.
\ No newline at end of file
......@@ -8,18 +8,20 @@ A second basic building block for UML diagrams is a _typed element_. Typed elem
The pattern for defining a typed element is:
```math
$$
\texttt{[visibility] element : type [constraint]}
$$
```
The optional $[visibility]$ indicates the visibility of the element, the $element$ is the name of the typed element, and the $type$ is its type, and the $[constraint]$ is an optional constraint.
The optional {{<math>}}$\texttt{[visibility]}${{</math>}} indicates the visibility of the element, the {{<math>}}$\texttt{element}${{</math>}} is the name of the typed element, and the {{<math>}}$\texttt{type}${{</math>}} is its type, and the {{<math>}}$\texttt{[constraint]}${{</math>}} is an optional constraint.
### Visibility
In UML _visibility_ (what we would call access level in C#) is indicated with symbols, i.e.:
* $\texttt{+}$ indicates `public`
* $\texttt{-}$ indicates `private`
* $\texttt{\#}$ indicates `protected`
* {{<math>}}$\texttt{+}${{</math>}} indicates `public`
* {{<math>}}$\texttt{-}${{</math>}} indicates `private`
* {{<math>}}$\texttt{#}${{</math>}} indicates `protected`
I.e. the field:
......@@ -29,23 +31,27 @@ protected int Size;
Would be expressed:
<div>
```math
$$
\texttt{# Size : int}
$$
</div>
```
### Constraints
A typed element can include a _constraint_ indicating some restriction for the element. The constraints are contained in a pair of curly braces after the typed element, and follow the pattern:
```math
$$
\texttt{ {element: boolean expression} }
$$
```
For example:
```math
$$
\texttt{- age: int {age: >= 0}}
$$
```
Indicates the private variable `age` must be greater than or equal to 0.
......@@ -7,7 +7,7 @@ date: 2018-08-24T10:53:26-05:00
In a UML class diagram, individual classes are represented with a box divided into three compartments, each of which is for displaying specific information:
![Class Diagram example]({{<static "images/5.5.1.png">}})
![Class Diagram example](/images/5.5.1.png)
The first compartment identifies the class - it contains the name of the class. The second compartment holds the _attributes_ of the class (in C#, these are the _fields_ and _properties_). And the third compartment holds the _operations_ of the class (in C#, these are the _methods_).
......@@ -18,17 +18,21 @@ The _attributes_ in UML represent the _state_ of an object. For C#, this would
We indicate fields with a typed element, i.e. in the example above, the `blended` field is represented with:
```math
$$
\text{-blended:bool}
\texttt{-blended:bool}
$$
```
Indicating it should be declared `private` with the type `bool`.
For properties, we add a stereotype containing either `get`, `set`, or both. I.e. if we were to expose the private field bool with a public accessor, we would add a line to our class diagram with:
```math
$$
\texttt{+Blended:bool<<get,set>>}
\texttt{+Blended:bool&lt;&lt;get,set&gt;&gt;}
$$
```
{{% notice info %}}
In C#, properties are technically methods. But we use the same syntax to utilize them as we do fields, and they serve the same role - to expose aspects of the class state. So for the purposes of this class we'll classify them as attributes.
......@@ -37,9 +41,11 @@ In C#, properties are technically methods. But we use the same syntax to utiliz
### Operators
The _operators_ in UML represent the _behavior_ of the object, i.e. the _methods_ we can invoke upon it. These are declared using the pattern:
```math
$$
\texttt{visibility name([parameter list])[:return type]}
$$
```
The $\texttt{[visibility]}$ uses the same symbols as typed elements, with the same correspondences. The $\texttt{name}$ is the name of the method, and the $\texttt{[parameter list]}$ is a comma-separated list of typed elements, corresponding to the parameters. The $\texttt{[:return type]}$ indicates the return type for the method (it can be omitted for void).
......@@ -54,9 +60,11 @@ public int Add(int a, int b)
Would be expressed:
```math
$$
\texttt{+Add(a:int, b:int):int}
$$
```
## Static and Abstract
In UML, we indicate a class is static by _underlining_ its name in the first compartment of the class diagram. We can similarly indicate static operators and methods is static by underlining the entire line referring to them.
......
......@@ -6,7 +6,7 @@ date: 2018-08-24T10:53:26-05:00
---
Class diagrams also express the associations _between_ classes by drawing lines between the boxes representing them.
![UML Association]({{<static "images/5.6.1.png">}})
![UML Association](/images/5.6.1.png)
There are two basic types of associations we model with UML: **has-a** and **is-a** associations. We break these into two further categories, based on the strength of the association, which is either **strong** or **weak**. These associations are:
......@@ -39,12 +39,12 @@ Is-a associations indicate a relationship where one class __is a__ instance of a
### Realization (Weak is-a)
Realization refers to making an interface "real" by implementing the methods it defines. For C#, this corresponds to a class that is implementing an `Interface`. We call this a **is-a** relationship, because the class is treated as being the type of the `Interface`. It is also a **weak** relationship as the same interface can be implemented by otherwise unrelated classes. In UML, realization is indicated by a dashed arrow in the direction of implementation:
![Realization in UML]({{<static "images/5.6.2.png">}})
![Realization in UML](/images/5.6.2.png)
### Generalization
Generalization refers to extracting the shared parts from different classes to make a *general* base class of what they have in common. For C# this corresponds to _inheritance_. We call this a **strong is-a** relationship, because the class has all the same state and behavior as the base class. In UML, realization is indicated by a solid arrow in the direction of inheritance:
![Generalization in UML]({{<static "images/5.6.3.png">}})
![Generalization in UML](/images/5.6.3.png)
Also notice that we show that `Fruit` and its `Blend()` method are abstract by italicizing them.
......@@ -54,12 +54,12 @@ Has-a associations indicates that a class holds one or more references to instan
### Aggregation
Aggregation refers to collecting references to other classes. As the aggregating class has references to the other classes, we call this a **has-a** relationship. It is considered **weak** because the aggregated classes are only collected by the aggregating class, and can exist on their own. It is indicated in UML by a solid line from the aggregating class to the one it aggregates, with an open diamond "fletching" on the opposite site of the arrow (the arrowhead is optional).
![Aggregation in UML]({{<static "images/5.6.4.png">}})
![Aggregation in UML](/images/5.6.4.png)
### Composition
Composition refers to assembling a class from other classes, "composing" it. As the composed class has references to the other classes, we call this a **has-a** relationship. However, the composing class typically _creates_ the instances of the classes composing it, and they are likewise destroyed when the composing class is destroyed. For this reason, we call it a **strong** relationship. It is indicated in UML by a solid line from the composing class to those it is composed of, with a solid diamond "fletching" on the opposite side of the arrow (the arrowhead is optional).
![Composition in UML]({{<static "images/5.6.5.png">}})
![Composition in UML](/images/5.6.5.png)
{{% notice info %}}
Aggregation and composition are commonly confused, especially given they both are defined by holding a variable or collection of another class type. An analogy I like to use to help students reason about the difference is this:
......@@ -72,11 +72,11 @@ In contrast, Composition is like an organism. Say we create a class representin
## Multiplicity
With aggregation and composition, we may also place numbers on either end of the association, indicating the number of objects involved. We call these numbers the _multiplicity_ of the association.
![Composition in UML]({{<static "images/5.6.5.png">}})
![Composition in UML](/images/5.6.5.png)
For example, the `Frog` class in the composition example has two instances of front and rear legs, so we indicate that each `Frog` instance (by a `1` on the Frog side of the association) has exactly two (by the `2` on the leg side of the association) legs. The tongue has a `1` to `1` multiplicity as each frog has one tongue.
![Aggregation in UML]({{<static "images/5.6.4.png">}})
![Aggregation in UML](/images/5.6.4.png)
Multiplicities can also be represented as a range (indicated by the start and end of the range separated by `..`). We see this in the `ShoppingCart` example above, where the count of `GroceryItems` in the cart ranges from 0 to infinity (infinity is indicated by an asterisk `*`).
......
......@@ -9,14 +9,14 @@ One of the many tools we can use to create UML diagrams is Microsoft Visio. For
Visio is a vector graphics editor for creating flowcharts and diagrams. it comes preloaded with a UML class diagram template, which can be selected when creating a new file:
![UML Class Diagram Template]({{<static "images/5.7.1.png">}})
![UML Class Diagram Template](/images/5.7.1.png)
Class diagrams are built by dragging shapes from the shape toolbox onto the drawing surface. Notice that the shapes include classes, interfaces, enumerations, and all the associations we have discussed. Once in the drawing surface, these can be resized and edited.
![Dragging Shapes]({{<static "images/5.7.2.gif">}})
![Dragging Shapes](/images/5.7.2.gif)
Right-clicking on an association will open a context menu, allowing you to turn on multiplicities. These can be edited by double-clicking on them. Unneeded multiplicities can be deleted.
![Setting Multiplicities]({{<static "images/5.7.3.gif">}})
![Setting Multiplicities](/images/5.7.3.gif)
To export a Visio project in PDF or other form, choose the "Export" option from the file menu.
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment