<commit_before>---
num: "h12"
desc: "The Decorator Pattern (HFDP 3), Serialization (HFJ 13)"
ready: false
assigned: 2016-07-19 09:30:00.00-7:00
due: 2016-07-20 09:30:00.00-7:00
---

This homework concerns <span data-hfdp="3">HFDP Chapter 3</span>, and <span data-hfj="13">HFJ Chapter 13</span>.
Please read those chapters, and then answer these questions.

<ol>

{% include hwk_li_name_10pts.html %}

<li style="margin-bottom:5em;">

In Chapter 3, the Open/Closed principle is presented in the context of
the Decorator pattern.  
<ol>
<li> (6 pts) Fill in the two blanks to result in the
statement of this principle.

<p style="margin-top:3em; font-size: 120%;">
Open for _______________________  closed for ___________________.
</p>
</li>

<li style="margin-bottom:8em;">(10 pts) Ok, that was the easy part; you just had to find the words in the chapter.  Now, the harder part: explain what this means in your own words.  "In your own words" means, don't just write down words for the book.   Read the book, then put the book down, and write what you've learned as if you were explaining it to someone.

</li>
</ol>

<div class="pagebreak"></div>
</li>

<li style="margin-bottom:1em;"> The decorator pattern features both
composition and inheritance. 

<ol>
<li style="margin-bottom:8em;"> (10 pts) How is composition used in the Decorator pattern?

</li>

<li style="margin-bottom:8em;"> (10 pts) How is inheritance used in
the Decorator pattern?  (Note: there is a particular purpose for which
inheritance is used in the Decorator pattern.   The book describes this very specifically.)
</li>

</ol>

</li>

<li style="margin-bottom:8em;"> (10 pts) The standard Java library classes that
implement input and output streams use the Decorator pattern.  Describe how the Decorator pattern is used here, and what benefits it provides. 
</li>


<li style="margin-bottom:5em;" markdown="1"> (4 pts) Suppose a certain object implements the `Serializable` interface.  There is some part of the object that should NOT be saved when serializing the object. How do you indicate this in your code? 
</li>

<li style="margin-bottom:8em;" markdown="1">
(15 pts) Write a brief `main` method that writes the string `Hello Disk!` to a file called `myFirstFile.txt`.  You only need the `main` method, not the enclosing class.   Be sure to account for any exceptions that must be declared or caught.
</li>



<li style="margin-bottom:8em;"> (10 pts) For this question, consider the reading in HFJ about serialization.

Your friend <NAME> says:

"I don't get why object serialization is such a big deal. You have a pointer to each object, and you know how many bytes it takes up in memory, and you know the objects type. Just write those bytes to a file, along with a few extra bytes indicating the type—problem solved. Then you read those bits back in and restore the objects. What's the big deal".
You however, see more deeply into the situation, and say:

"Well, B.C., it isn't quite that simple. You are forgetting a few subtle issues—things you should realize from your previous study of how data structures work—things you should have learned in CS16 and CS24. Even though those were C/C++ courses, the same problems are going to arise in Java."
B.C. says: "I don't see what you are getting at. Can you explain it to me?"

What do you say to B.C. to help him/her realize why Object Serialization is more subtle than just writing out all the bits exactly as they are, and reading them back in exactly as they are?

HINT: Think about things like linked lists, pointers, and references, and how they are implemented in both C++ and Java.

</li>
</ol>

<div style="display:none">
http://UCSB-CS56-M16.github.io/hwk/h12
</div>




<commit_msg>Update h12.md<commit_after>---
num: "h12"
desc: "The Decorator Pattern (HFDP 3), Serialization (HFJ 13)"
ready: false
assigned: 2016-07-19 09:30:00.00-7:00
due: 2016-07-20 09:30:00.00-7:00
---

This homework concerns <span data-hfdp="3">HFDP Chapter 3</span>, and <span data-hfj="13">HFJ Chapter 13</span>.
Please read those chapters, and then answer these questions.

<ol>

{% include hwk_li_name_10pts.html %}

<li style="margin-bottom:5em;">

In Chapter 3, the Open/Closed principle is presented in the context of
the Decorator pattern.  
<ol>
<li> (8 pts) Fill in the two blanks to result in the
statement of this principle.

<p style="margin-top:3em; font-size: 120%;">
Open for _______________________  closed for ___________________.
</p>
</li>

<li style="margin-bottom:8em;">(10 pts) Ok, that was the easy part; you just had to find the words in the chapter.  Now, the harder part: explain what this means in your own words.  "In your own words" means, don't just write down words for the book.   Read the book, then put the book down, and write what you've learned as if you were explaining it to someone.

</li>
</ol>

<div class="pagebreak"></div>
</li>

<li style="margin-bottom:1em;"> The decorator pattern features both
composition and inheritance. 

<ol>
<li style="margin-bottom:8em;"> (10 pts) How is composition used in the Decorator pattern?

</li>

<li style="margin-bottom:8em;"> (10 pts) How is inheritance used in
the Decorator pattern?  (Note: there is a particular purpose for which
inheritance is used in the Decorator pattern.   The book describes this very specifically.)
</li>

</ol>

</li>

<li style="margin-bottom:8em;"> (10 pts) The standard Java library classes that
implement input and output streams use the Decorator pattern.  Describe how the Decorator pattern is used here, and what benefits it provides. 
</li>


<li style="margin-bottom:5em;" markdown="1"> (6 pts) Suppose a certain object implements the `Serializable` interface.  There is some part of the object that should NOT be saved when serializing the object. How do you indicate this in your code? 
</li>

<li style="margin-bottom:8em;" markdown="1">
(20 pts) Write a brief `main` method that writes the string `Hello Disk!` to a file called `myFirstFile.txt`.  You only need the `main` method, not the enclosing class.   Be sure to account for any exceptions that must be declared or caught.
</li>



<li style="margin-bottom:8em;"> (10 pts) For this question, consider the reading in HFJ about serialization.

Your friend <NAME> says:

"I don't get why object serialization is such a big deal. You have a pointer to each object, and you know how many bytes it takes up in memory, and you know the objects type. Just write those bytes to a file, along with a few extra bytes indicating the type—problem solved. Then you read those bits back in and restore the objects. What's the big deal".
You however, see more deeply into the situation, and say:

"Well, B.C., it isn't quite that simple. You are forgetting a few subtle issues—things you should realize from your previous study of how data structures work—things you should have learned in CS16 and CS24. Even though those were C/C++ courses, the same problems are going to arise in Java."
B.C. says: "I don't see what you are getting at. Can you explain it to me?"

What do you say to B.C. to help him/her realize why Object Serialization is more subtle than just writing out all the bits exactly as they are, and reading them back in exactly as they are?

HINT: Think about things like linked lists, pointers, and references, and how they are implemented in both C++ and Java.

</li>
</ol>

<div style="display:none">
http://UCSB-CS56-M16.github.io/hwk/h12
</div>





{'fraction_non_alphanumeric': 0.094873859366613, 'fraction_numerical': 0.024691358024691357, 'mean_word_length': 4.267137809187279, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5120147', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2177, 'n_words': 1113}