<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Simple question' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Simple question' posted on the 'Object Orientation' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Mon, 17 Jun 2013 21:41:31 -0700</pubDate>
    <lastBuildDate>Mon, 17 Jun 2013 21:41:31 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Simple question</title>
      <link>http://www.programmersheaven.com/mb/objects/208170/208170/simple-question/</link>
      <description>Hi there,&lt;br /&gt;
&lt;br /&gt;
I have a simple question involving member inheritance in Java; I was wondering what the best way of tackling this sort of design issue is. I will describe an example.&lt;br /&gt;
&lt;br /&gt;
There are two types of Gun, a simple one, used by Soldiers:&lt;br /&gt;
&lt;br /&gt;
class Gun {}&lt;br /&gt;
&lt;br /&gt;
and an advanced one, SilencedGun which only Commanders can use. SilencedGun is a subclass of Gun:&lt;br /&gt;
&lt;br /&gt;
class SilencedGun extends Gun { }&lt;br /&gt;
&lt;br /&gt;
Now, a Soldier is defined as:&lt;br /&gt;
class Soldier {&lt;br /&gt;
???? Gun gun; // see later&lt;br /&gt;
&lt;br /&gt;
  public void setGun(Gun g) {&lt;br /&gt;
    gun = g;&lt;br /&gt;
  }&lt;br /&gt;
  public Gun getGun() {&lt;br /&gt;
   return gun;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Commander extends Soldier {&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
My question is this: How do we best code a Commander class, such that only SilencedGuns can be possessed by a commander, and never simply a Gun? If we leave the Commander class empty, then any client can call commander.setGun(new Gun()), which we don't want to happen. What access specifier should gun in the parent class have?&lt;br /&gt;
&lt;br /&gt;
Should I overwrite gun in Commander to be of type SilencedGun, and then add new get/set of type SilencedGun? Will that stop clients calling the superclass methods?&lt;br /&gt;
&lt;br /&gt;
What is the best solution to this sort of issue?&lt;br /&gt;
&lt;br /&gt;
Thanks for suggestions.&lt;br /&gt;
GS&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/objects/208170/208170/simple-question/</guid>
      <pubDate>Thu, 21 Aug 2003 14:49:41 -0700</pubDate>
      <category>Object Orientation</category>
    </item>
    <item>
      <title>Re: Simple question</title>
      <link>http://www.programmersheaven.com/mb/objects/208170/236853/re-simple-question/#236853</link>
      <description>: Hi there,&lt;br /&gt;
: &lt;br /&gt;
: I have a simple question involving member inheritance in Java; I was wondering what the best way of tackling this sort of design issue is. I will describe an example.&lt;br /&gt;
: &lt;br /&gt;
: There are two types of Gun, a simple one, used by Soldiers:&lt;br /&gt;
: &lt;br /&gt;
: class Gun {}&lt;br /&gt;
: &lt;br /&gt;
: and an advanced one, SilencedGun which only Commanders can use. SilencedGun is a subclass of Gun:&lt;br /&gt;
: &lt;br /&gt;
: class SilencedGun extends Gun { }&lt;br /&gt;
: &lt;br /&gt;
: Now, a Soldier is defined as:&lt;br /&gt;
: class Soldier {&lt;br /&gt;
: ???? Gun gun; // see later&lt;br /&gt;
: &lt;br /&gt;
:   public void setGun(Gun g) {&lt;br /&gt;
:     gun = g;&lt;br /&gt;
:   }&lt;br /&gt;
:   public Gun getGun() {&lt;br /&gt;
:    return gun;&lt;br /&gt;
:   }&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: class Commander extends Soldier {&lt;br /&gt;
: ...&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: My question is this: How do we best code a Commander class, such that only SilencedGuns can be possessed by a commander, and never simply a Gun? If we leave the Commander class empty, then any client can call commander.setGun(new Gun()), which we don't want to happen. What access specifier should gun in the parent class have?&lt;br /&gt;
: &lt;br /&gt;
: Should I overwrite gun in Commander to be of type SilencedGun, and then add new get/set of type SilencedGun? Will that stop clients calling the superclass methods?&lt;br /&gt;
: &lt;br /&gt;
: What is the best solution to this sort of issue?&lt;br /&gt;
: &lt;br /&gt;
: Thanks for suggestions.&lt;br /&gt;
: GS&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/objects/208170/236853/re-simple-question/#236853</guid>
      <pubDate>Fri, 16 Jan 2004 02:25:11 -0700</pubDate>
      <category>Object Orientation</category>
    </item>
    <item>
      <title>Re: Simple question</title>
      <link>http://www.programmersheaven.com/mb/objects/208170/236856/re-simple-question/#236856</link>
      <description>If you create the empty class that extends another class it will be full equvalent of the class from which it was derived. The derived class define a subset of the base class instances. So it need somehow define the differences for or it will be just another name of one. So both the silGun and commander has to have something additionaly defined to differenciate from their base classes. The main idea of OOP related to reuse and economizing effords of programmers is overwriting of functions in the extended/derived class. So the subroutines for processing of base class instances automatically are changed when processing elements/instances of the subset/derived/extended class. &lt;br /&gt;
In your example the main question is how you define the silence gun difference from gun in terms of class definition. I would not be surprised if actually it can happen that both sil gun and soldjer gun should be derived from a vase gun, or silence gun should be base for Gun. The comon mistake is to think that class design is something simple. Actually it is requres the highest level of programming skills to be eficient. I saw already projects when unskilled use of OOP made&lt;br /&gt;
the logic absolutely ununderstandable and large bad performing filled by errors programs. &lt;br /&gt;
&lt;br /&gt;
: : Hi there,&lt;br /&gt;
: : &lt;br /&gt;
: : I have a simple question involving member inheritance in Java; I was wondering what the best way of tackling this sort of design issue is. I will describe an example.&lt;br /&gt;
: : &lt;br /&gt;
: : There are two types of Gun, a simple one, used by Soldiers:&lt;br /&gt;
: : &lt;br /&gt;
: : class Gun {}&lt;br /&gt;
: : &lt;br /&gt;
: : and an advanced one, SilencedGun which only Commanders can use. SilencedGun is a subclass of Gun:&lt;br /&gt;
: : &lt;br /&gt;
: : class SilencedGun extends Gun { }&lt;br /&gt;
: : &lt;br /&gt;
: : Now, a Soldier is defined as:&lt;br /&gt;
: : class Soldier {&lt;br /&gt;
: : ???? Gun gun; // see later&lt;br /&gt;
: : &lt;br /&gt;
: :   public void setGun(Gun g) {&lt;br /&gt;
: :     gun = g;&lt;br /&gt;
: :   }&lt;br /&gt;
: :   public Gun getGun() {&lt;br /&gt;
: :    return gun;&lt;br /&gt;
: :   }&lt;br /&gt;
: : }&lt;br /&gt;
: : &lt;br /&gt;
: : class Commander extends Soldier {&lt;br /&gt;
: : ...&lt;br /&gt;
: : }&lt;br /&gt;
: : &lt;br /&gt;
: : My question is this: How do we best code a Commander class, such that only SilencedGuns can be possessed by a commander, and never simply a Gun? If we leave the Commander class empty, then any client can call commander.setGun(new Gun()), which we don't want to happen. What access specifier should gun in the parent class have?&lt;br /&gt;
: : &lt;br /&gt;
: : Should I overwrite gun in Commander to be of type SilencedGun, and then add new get/set of type SilencedGun? Will that stop clients calling the superclass methods?&lt;br /&gt;
: : &lt;br /&gt;
: : What is the best solution to this sort of issue?&lt;br /&gt;
: : &lt;br /&gt;
: : Thanks for suggestions.&lt;br /&gt;
: : GS&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/objects/208170/236856/re-simple-question/#236856</guid>
      <pubDate>Fri, 16 Jan 2004 03:06:37 -0700</pubDate>
      <category>Object Orientation</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/objects/208170/390608/this-post-has-been-deleted/#390608</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/objects/208170/390608/this-post-has-been-deleted/#390608</guid>
      <pubDate>Thu, 07 May 2009 23:49:42 -0700</pubDate>
      <category>Object Orientation</category>
    </item>
    <item>
      <title>Re: Simple question</title>
      <link>http://www.programmersheaven.com/mb/objects/208170/395571/re-simple-question/#395571</link>
      <description>That's a text book perfect answer!&lt;br /&gt;
&lt;br /&gt;
I'm looking for a full life cycle Software Development book. &lt;br /&gt;
Can you recommend one?&lt;br /&gt;
&lt;br /&gt;
Cheers&lt;br /&gt;
&lt;br /&gt;
Kris&lt;br /&gt;
&lt;a href="http://www.kremsoft.com"&gt;http://www.kremsoft.com&lt;/a&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/objects/208170/395571/re-simple-question/#395571</guid>
      <pubDate>Sat, 22 Aug 2009 12:34:05 -0700</pubDate>
      <category>Object Orientation</category>
    </item>
  </channel>
</rss>