Click here to Skip to main content
15,851,090 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
In the Address class there are three constructors that shall be made​​. I do not quite understand what it should look like. Down below it says how to write these constructors.


  1. Can someone help me as I am new to C#?
  2. What does this requirement mean: "The field m_strErrMessage is meant to contain eventual errors. It should be emptied after the message is used"?.
  3. Why should it contain errors and what would be the benefit from that?
  4. Can somenone please help me? (see list item 1.)


Here is the explanation of what I should do.

Excerpt from my assignement:
5.1 Fields: As in the Address class diagram. The field m_strErrMessage is
meant to contain eventual errors. It should be emptied after the message
is used.
5.2 Constructors:
5.2.1 Write three constructors as follows:
5.2.2 One default constructor in which you assign all instance
variables of the type string to string.Empty. This is to avoid
null-problem with strings.
5.2.3 One constructor with 4 parameters:
public Address(string street, string zip, string city, Countries country)
5.2.4 A constructor with 3 parameters, eliminating country from the above.


Thanks for letting me waste your time with stuff I should do!
Posted
Updated 3-Nov-11 10:12am
v3
Comments
ARBebopKid 3-Nov-11 14:57pm    
Homework?

 
Share this answer
 
Comments
[no name] 3-Nov-11 16:14pm    
Nice link.

Although, as I said to griff IMO this is an honest question on homework. The poster is not asking for anyone to do it. He is asking for some understanding. As much as we all love to be sarcastic some HW posts do deserve a little attention. Someday you could very well be working for these new recruits. Or someday you could simply be working with them.

Its like the old saying "give a man a fish... teach a man to fish..."

Well it seems that the 'elite' CPers choose to chuck young cadets fishing poles in the water, even though they are just asking how to bait the hook.

Granted 99% of HW posts are "Gimme Codz plz" and should be giving the greatest sarcastic remark. But the other 1% do deserve some thought. Not saying his question(s) are well written, but to me it is clear he is not asking for code or how to do it. More of a why. We were all there once, but for most of use communities like CP didn't exist.

Imagine how would have developed your skills if they did exist and provided good support (not answer giving but guidance).
Sergey Alexandrovich Kryukov 3-Nov-11 20:29pm    
As always in such cases, this is an adequate response, my 5.
--SA

  1. Yes.
  2. It means that the author of the requirements is hardly familiar with best software design practices and even with (good) Microsoft naming conventions. (See also the response by Griff.) As to you, you cannot even picture the reader of you question and provide sufficient portion of information.
  3. In general case, it should not; and nobody will get any benefits.
  4. See item 1.


As to the items from your assignment, they make no sense unless one explains the main goal of the code. Also, you never asked a single question about this part.

—SA
 
Share this answer
 
v3
If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Having said that, I will explain your first query, because that is related to not understanding the task, rather than doing your homework.

What he means is that the m_strErrMessage will be given a message to report an error - and this it should be cleared once either the error has been handled, or (presumably) once it has been reported. This is normally to prevent it being reported repeatedly.

BTW: m_strErrMessage is bad practice for naming conventions in C#: the "m_" prefix indicate a member of a class (which isn't used in C# names), the "str" indicates the variable datatype (which again is not used) and the name should probably be either ErrorMessage or errorMessage depending on whether it is property or an internal field.

The second part regrading the constructors is pretty easy: it spells out what you have to do in the question in considerable detail! :laugh:
 
Share this answer
 
Comments
Manfred Rudolf Bihy 3-Nov-11 15:16pm    
Griff, Griff! :sadly shakes head:
The 1st query is if somebody can help OP. Exactly the same as the 4th. So you must have meant the 2nd query.
I sorely miss the "Do you want fries with that?" part! :)

Anyways, take a five!
Sergey Alexandrovich Kryukov 3-Nov-11 20:34pm    
True, but... such a small detail... :-). Everything is bad in this case, unfortunately. Please see my answer as well.
--SA
[no name] 3-Nov-11 15:29pm    
IMHO it seems the Op was not trying to hide that it is homework. More importantly he never said "Plz gimme codz!"

He simply did not understand some of the 101 concepts (and did start his post out with acknowledgin it) and asked for help understanding them.

4 from me. You did provide some info to help :)
Sergey Alexandrovich Kryukov 3-Nov-11 20:33pm    
I voted 5 but in part I agree with you, Collin. OP should not be blamed 100%, just because it looks like the person who provided the assignment and requirement is hardly qualified to teach the subject. This idea is actually supported by Griff's notes, in particular on m_strErrMessage which I agree with, please see my answer as well.

Sad but true.
--SA
1.) Yes, there are lots of people that can help you.

2.) Strings are reference types, which means that if another object receives it and puts data in it, any objects that have references to it can access that same data. One can pass the string to a constructor or initializer and after the initializer check the string for null or string.Empty. If these are not true then you need to do something with the error like log it or display it. Since you would not want to continually log it, once it is logged it should be emptied or nulled out.

3.) Any code could generate errors so it is best practice to anticipate them. Just for the sake of argument you could say that the constructor could fail because a Zip code is invalid or the country is not in the correct region. It doesn't really matter why it fails, but the fact that your code is set up to log it or display it appropriately.

4.) See 1 :)
 
Share this answer
 
Comments
Goran Shoan 3-Nov-11 15:52pm    
Collin you mean that the error method would declare every possible error that can occur so it is gathered in one single method??
[no name] 3-Nov-11 16:06pm    
Not sure what you are implying. The requirements of the OP are that a field of string m_strErrMessage be used. How it is filled or gathered is irrelevant. I simply gave an example since he asked what does the requirement mean (see number 2).

I personally think it is silly to have a single error holder because you will waist time building it with deliminators and then parsing it. Why not use a collection? Or better yet Why not inject an error logger?

Well the answer to both of these is because it is a teaching example.

Have to start from somewhere. It is difficult to teach best practices when the individuals have no practice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900