Click here to Skip to main content
15,886,199 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
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 
What is your way of dealing with a composition in a class?
Will you force the user to pass the required values to the contained objects?
Or you'll let the user set the contained object anytime later and check for it's validity everywhere?

For example,
class Rocket
{
  Booster b1;
  Rocket(Boostertype bt, BoosterPower bp)
  {
   //check bp & bt values for acceptable range else throw an exception
    b1 = new Booster(bt,bp);
  }
  Launch()
 {
  b1.fire();
  //We are sure Booster is initialized
 }
}


Or it could be done this way

class Rocket
{
  Booster b1;
  Rocket()
  {
    
  }
  initBooster(Boostertype bt, BoosterPower bp)
 {
   
    b1 = new Booster(bt,bp);
 }
  Launch()
 { 
   if(null!=b1)
   {
     if(b1.bp >100)
     {
     //Ok to launch
      }
   }
  // booster may not be initialized yet. so check and throw an exception if not inited.
 }
}


My preferred way is to enforce Rocket's constructor with params required for booster as well.
Unless we pass a sensible value for the booster, rocket creation will fail.

But my mate here seem to differ with my opinion. He doesn't want Rocket's creation to be disturbed by booster constructors parameters.

Instead, when a Launch() is called , it should throw an exception saying Booster is not initialized/configured.

Which one would you prefer?

Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

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 
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 
GeneralRe: Simple composition - Your thoughts? Pin
Marc Clifton15-May-12 4:57
mvaMarc Clifton15-May-12 4:57 
GeneralRe: Simple composition - Your thoughts? Pin
Eytukan15-May-12 4:41
Eytukan15-May-12 4:41 
GeneralRe: Simple composition - Your thoughts? Pin
Marc Clifton15-May-12 5:06
mvaMarc Clifton15-May-12 5:06 
GeneralRe: Simple composition - Your thoughts? Pin
Eytukan15-May-12 18:32
Eytukan15-May-12 18:32 
QuestionDatabase Modeling - Conditional Relationships Pin
Leslie Sanford11-May-12 8:34
Leslie Sanford11-May-12 8:34 

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.