Commit 18a15aa8 authored by Dr. Martin Goik's avatar Dr. Martin Goik

Cosmetics

parent 271666bc
......@@ -3902,27 +3902,64 @@ seconds = 23</screen></td>
</itemizedlist>
</figure>
<figure xml:id="sd1_fig_MemberConstructorImplement">
<title>Implementing club members.</title>
<programlisting language="java">public class ClubMember {
final private String name;
public ClubMember(final String name) {
this.name = name;
}
public String getDetails() {
return "Member " + name;
}
}</programlisting>
</figure>
<figure xml:id="sd1_fig_MembershipInfo">
<title>Showing membership info.</title>
<informaltable border="0">
<tr>
<td valign="top"><programlisting language="java">final ClubMember
john = new ClubMember("John"),
karen = new ClubMember("Karen");
System.out.println(john.getDetails());
System.out.println(karen.getDetails());
</programlisting></td>
<td valign="top"><screen>Member John
Member Karen</screen></td>
</tr>
</informaltable>
</figure>
<figure xml:id="sd1_fig_staticMemberConstructorImplement">
<title>Implementing membership numbers.</title>
<programlisting language="java">public class ClubMember {
<programlisting language="java">emphapublic class ClubMember {
static <co linkends="sd1_callout_clubStaticMembercount-1"
xml:id="sd1_callout_clubStaticMembercount-1-co"/> private int memberCount = 0;
<emphasis role="red">static</emphasis> <co
linkends="sd1_callout_clubStaticMembercount-1"
xml:id="sd1_callout_clubStaticMembercount-1-co"/> <emphasis
role="red">private int memberCount = 0;</emphasis>
final private int memberNumber; <co
<emphasis role="red">final private int memberNumber;</emphasis> <co
linkends="sd1_callout_clubStaticMembercount-2"
xml:id="sd1_callout_clubStaticMembercount-2-co"/>
final private String name;
public ClubMember(final String name) {
this.name = name;
memberNumber = ++memberCount; <co
<emphasis role="red">memberNumber = ++memberCount;</emphasis> <co
linkends="sd1_callout_clubStaticMembercount-3"
xml:id="sd1_callout_clubStaticMembercount-3-co"/>
}
public String getDetails() {
return "Member " + name + ", member number " + memberNumber <co
return "Member " + name <emphasis role="red">+ ", member number " + memberNumber</emphasis> <co
linkends="sd1_callout_clubStaticMembercount-4"
xml:id="sd1_callout_clubStaticMembercount-4-co"/>;
}
......@@ -3947,25 +3984,25 @@ seconds = 23</screen></td>
<callout arearefs="sd1_callout_clubStaticMembercount-3-co"
xml:id="sd1_callout_clubStaticMembercount-3">
<para>Whenever a new instance of <classname>ClubMember</classname>
is being created two things happen:</para>
<para>On creating a new instance of
<classname>ClubMember</classname> two actions happen:</para>
<orderedlist>
<listitem>
<para>The overall <varname>memberCount</varname> variable is
being incremented.</para>
being incremented by one.</para>
</listitem>
<listitem>
<para>The new club's member count is being assigned to the
current instance.</para>
<para>The new club's overall member count is being assigned to
the current instance.</para>
</listitem>
</orderedlist>
</callout>
<callout arearefs="sd1_callout_clubStaticMembercount-4-co"
xml:id="sd1_callout_clubStaticMembercount-4">
<para>Accessing an instance's membership number.</para>
<para>Accessing an individual member's membership number.</para>
</callout>
</calloutlist>
</figure>
......@@ -3973,19 +4010,23 @@ seconds = 23</screen></td>
<figure xml:id="sd1_fig_staticMembershipNumberInfo">
<title>Showing membership numbers.</title>
<programlisting language="java">public static void main(String[] args) {
final ClubMember john = new ClubMember("John"),
karen = new ClubMember("Karen");
<informaltable border="0">
<tr>
<td valign="top"><programlisting language="java">final ClubMember
john = new ClubMember("John"),
karen = new ClubMember("Karen");
System.out.println(karen.getDetails());
}</programlisting>
System.out.println(john.getDetails());
System.out.println(karen.getDetails());</programlisting></td>
<screen>Member Karen, member number 2</screen>
<td valign="top"><screen>Member John, member number 1
Member Karen, member number 2</screen></td>
</tr>
</informaltable>
</figure>
<figure xml:id="sd1_fig_staticAccessorMemberCount">
<title>Access to the club's overall member count?</title>
<title>Accessing the club's overall member count?</title>
<programlisting language="java">public class ClubMember {
......@@ -4024,19 +4065,23 @@ seconds = 23</screen></td>
<figure xml:id="sd1_fig_staticAccessMemberCountImplement">
<title>Accessing the club's member count</title>
<programlisting language="java">final ClubMember
<informaltable border="0">
<tr>
<td valign="top"><programlisting language="java">final ClubMember
john = new ClubMember("John"),
karen = new ClubMember("Karen"),
petra = new ClubMember("Petra");
System.out.println(karen.getDetails());
System.out.println(karen.getDetails());
System.out.println("Club's member count:" +
ClubMember.getMemberCount()); // Good: Prevent tampering
} // memberCount variable.</programlisting>
System.out.println("Club's member count:" +
ClubMember.getMemberCount());// Good: Prevent tampering
// memberCount variable.</programlisting></td>
<screen>Member Karen, member number 2
Club's member count:3</screen>
<td valign="top"><screen>Member Karen, member number 2
Club's member count:3</screen></td>
</tr>
</informaltable>
</figure>
<figure xml:id="sd1_fig_staticNoInstanceNeeded">
......@@ -4062,7 +4107,7 @@ System.out.println("Maximum: " +
</tr>
</informaltable>
<para>Observation: Object state irrelevant.</para>
<para>Observation: Instance state irrelevant.</para>
</figure>
<figure xml:id="sd1_fig_staticStateIndependentMethods">
......@@ -4196,10 +4241,11 @@ model/ClubMember.java:20: error: non-static variable memberNumber
number. <code language="java">static</code> methods are being
defined on class rather than on instance level. According to
<xref linkend="sd1_fig_syntaxAccessClassMembersMethodDef"/>
execution happens by calling ClubMember.getDetails(). Thus
there is no instance involved and thus both instance variables
<emphasis role="red">name</emphasis> and <emphasis
role="red">memberNumber</emphasis> are invisible.</para>
execution happens by calling ClubMember.getDetails(). There is
thus no instance involved and consequently both instance
variables <emphasis role="red">name</emphasis> and <emphasis
role="red">memberNumber</emphasis> do not exist in any static
context.</para>
</listitem>
<listitem>
......@@ -4229,8 +4275,8 @@ System.out.println("Club's headcount:" + <emphasis role="red">john.</emphasis>ge
<para>This is actually a regression with respect to the <code
language="java">static</code> class method variant since the
number of club members in fact does not depend on individual
member instances.</para>
number of club members in fact does not depend on any
individual member instance. </para>
<para>We may reveal this changes futility by:</para>
......@@ -4250,8 +4296,8 @@ System.out.println("Club's headcount:" + <emphasis role="red">petra</emphasis>.g
<para>Even worse: Without creating an instance of
<classname>ClubMember</classname> we can no longer access the
club's overall member count. But even without any member we
still do have a valid member count of zero.</para>
club's overall member count. But even without any member
instance we still have a valid member count of zero.</para>
</listitem>
</orderedlist>
</answer>
......
Markdown is supported
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