Click here to Skip to main content
15,913,100 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: Localization - market possibilities vs. custom tool Pin
Eddy Vluggen21-May-12 4:59
professionalEddy Vluggen21-May-12 4:59 
GeneralRe: Localization - market possibilities vs. custom tool Pin
hoernchenmeister21-May-12 5:11
hoernchenmeister21-May-12 5:11 
GeneralRe: Localization - market possibilities vs. custom tool Pin
Eddy Vluggen21-May-12 6:54
professionalEddy Vluggen21-May-12 6:54 
GeneralRe: Localization - market possibilities vs. custom tool Pin
hoernchenmeister21-May-12 21:11
hoernchenmeister21-May-12 21:11 
GeneralRe: Localization - market possibilities vs. custom tool Pin
Eddy Vluggen22-May-12 0:48
professionalEddy Vluggen22-May-12 0:48 
AnswerRe: Localization - market possibilities vs. custom tool Pin
Bernhard Hiller22-May-12 3:18
Bernhard Hiller22-May-12 3:18 
GeneralRe: Localization - market possibilities vs. custom tool Pin
hoernchenmeister22-May-12 4:32
hoernchenmeister22-May-12 4:32 
QuestionHandling errors - What is a good balance? Pin
Troy.compdr17-May-12 7:50
Troy.compdr17-May-12 7:50 
AnswerRe: Handling errors - What is a good balance? Pin
jschell17-May-12 11:16
jschell17-May-12 11:16 
AnswerRe: Handling errors - What is a good balance? Pin
Luc Pattyn17-May-12 12:20
sitebuilderLuc Pattyn17-May-12 12:20 
AnswerRe: Handling errors - What is a good balance? Pin
RobCroll18-May-12 2:48
RobCroll18-May-12 2:48 
AnswerRe: Handling errors - What is a good balance? Pin
Ron Beyer24-May-12 17:40
professionalRon Beyer24-May-12 17:40 
QuestionSimple composition - Your thoughts? Pin
Eytukan14-May-12 23:15
Eytukan14-May-12 23:15 
AnswerRe: Simple composition - Your thoughts? Pin
Nagy Vilmos14-May-12 23:38
professionalNagy Vilmos14-May-12 23:38 
GeneralRe: Simple composition - Your thoughts? Pin
Eytukan14-May-12 23:43
Eytukan14-May-12 23:43 
AnswerRe: Simple composition - Your thoughts? Pin
Pete O'Hanlon14-May-12 23:48
mvePete O'Hanlon14-May-12 23:48 
GeneralRe: Simple composition - Your thoughts? Pin
Nagy Vilmos15-May-12 1:25
professionalNagy Vilmos15-May-12 1:25 
GeneralRe: Simple composition - Your thoughts? Pin
Pete O'Hanlon15-May-12 1:56
mvePete O'Hanlon15-May-12 1:56 
Nagy Vilmos wrote:
If the rocket must have a booster, then I agree it must be a part of the
constructor to ensure its presence.

And that's the rub. What constitues a valid instance of the class? In the admittedly contrived example given, the only operation that could be performed was a Launch, so the booster is an intrinsic part of this particular example.

Now, if this class were one I was designing, I would take a slightly different approach if this was a full lifecycle of a rocket. This particular rocket implementation is tightly coupled to a single booster. What happens if I want a rocket with more than one booster? Or I want to use one that's based on the ACME Fusion Drive 3000 elastic band? To that end, I'd consider that a design like this might be better:
C#
public class Rocket
{
  public Rocket()
  {
  }

  public void PreLaunchTests()
  {
    OnPreLaunchTests();
  }

  public void Launch()
  {
  }

  protected virtual void OnPreLaunchTests()
  {
  }

  protected virtual void OnLaunch()
  {
  }
}

public class SingleBoosterRocket : Rocket
{
  public List<IBooster> Boosters { get; private set; }

  public SingleBoosterRocket()
  {
    Boosters = new List<IBooster>();
  }

  public void AddBooster(IBooster booster)
  {
    Boosters.Add(booster);
  }

  protected override void OnPreLaunchTests()
  {
    // Do some pre launch tests.
  }

  protected override void OnLaunch()
  {
    if (Boosters.Count == 0)
      throw new NotEnoughBoostersException();
    // Do some other work.
  }
}

public class DualBoosterRocket : SingleBoosterRocket
{

  public DualBoosterRocket() : base()
  {
  }

  protected override void OnPreLaunchTests()
  {
    // Do some pre launch tests.
  }

  protected override void OnLaunch()
  {
    if (Boosters.Count < 2)
      throw new NotEnoughBoostersException();
    // Do some other work.
  }
}
Again, this is a completely fabricated design, but this has the advantage of being more flexible. Ultimately, the design should be based on the real requirements, which is why I have steered well clear of saying that one approach is better than another in all cases. BTW - in case you're wondering, the actual composition in this sample has been moved to the containing object, rather than the actual rocket implementation, as that piece of code would be the one that decided what the composition entailed. The rules for the rocket have been encapsulated in a simple classes that have a single responsibility.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Simple composition - Your thoughts? Pin
Eytukan15-May-12 4:36
Eytukan15-May-12 4:36 
GeneralRe: Simple composition - Your thoughts? Pin
Pete O'Hanlon15-May-12 4:53
mvePete O'Hanlon15-May-12 4:53 
AnswerRe: Simple composition - Your thoughts? Pin
BobJanova15-May-12 0:46
BobJanova15-May-12 0:46 
AnswerRe: Simple composition - Your thoughts? Pin
Marc Clifton15-May-12 1:51
mvaMarc Clifton15-May-12 1:51 
GeneralRe: Simple composition - Your thoughts? Pin
Pete O'Hanlon15-May-12 1:57
mvePete O'Hanlon15-May-12 1:57 
GeneralRe: Simple composition - Your thoughts? Pin
Marc Clifton15-May-12 2:45
mvaMarc Clifton15-May-12 2:45 
GeneralRe: Simple composition - Your thoughts? Pin
Pete O'Hanlon15-May-12 3:25
mvePete O'Hanlon15-May-12 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.