@b1xml2 said:
ignore my last post...it has been a tiring day =)
Ok, because otherwise I would point out that your code would'nt even compile, because your return the wrong type!
@b1xml2 said:
ignore my last post...it has been a tiring day =)
Ok, because otherwise I would point out that your code would'nt even compile, because your return the wrong type!
Actually, that's a great statement: "real documentation is source code". Thanks.
But I agree in this case, the methode isEmpty should have had the following comment:
<FONT color=#008000>// Return the oposite of what you think it does!</FONT>
Well, I finished your app (had nothing to do):
<FONT face="Courier New" size=1>public class MyClass {
public static void Main()
{
CarWash.WashCar(new Car("abc"));
CarWash.WashCar(new Car("123"), true);
CarWash.WashCar(new Car("a car"));
Console.ReadLine();
}
public class Car {
string _licensePlate;
public Car(string licensePlate) {
_licensePlate = licensePlate;
}
public override string ToString() {
return _licensePlate;
}
}
public class CarWash {
public static void WashCar(Car car) {
WashCar(car, false);
}
public static void WashCar(Car car, bool wax) {
Console.WriteLine("Start washing...");
Console.WriteLine("Washing car {0}!", car);
if(wax) Console.WriteLine("Waxing car {0}!", car);
Console.WriteLine("Car washed.");
}
}
}</FONT>
This discussion is reminding me of the following joke:
<!-- When using this boilerplate, remember to replace the "JokeTITLE" in both places above. And if it's a song, not a joke, change that word in the Disclaimer. <p dir="auto">HERE IS THE BODY OF THE JOKE<br /> -->How the way people code "Hello World" varies depending on their age and job: </P></p> <H4>High School/Jr.High</H4><PRE> 10 PRINT "HELLO WORLD" 20 END </PRE> <H4>First year in College</H4><PRE> program Hello(input, output) begin writeln('Hello World') end. </PRE> <H4>Senior year in College</H4><PRE> (defun hello (print (cons 'Hello (list 'World)))) </PRE> <H4>New professional</H4><PRE> #include <stdio.h> <p dir="auto">void main(void)<br /> {<br /> char *message[] = {"Hello ", "World"};<br /> int i;<br /> for(i = 0; i < 2; ++i)<br /> printf("%s", message[i]);<br /> printf("\n");<br /> }</p> </PRE> <H4>Seasoned professional</H4><PRE> #include <iostream.h> #include <string.h> class string { private: int size; char *ptr; public: string() : size(0), ptr(new char('\0')) {} string(const string &s) : size(s.size) { ptr = new char[size + 1]; strcpy(ptr, s.ptr); } ~string() { delete [] ptr; } friend ostream &operator <<(ostream &, const string &); string &operator=(const char *); }; <p dir="auto">ostream &operator<<(ostream &stream, const string &s)<br /> {<br /> return(stream << s.ptr);<br /> }<br /> string &string::operator=(const char *chrs)<br /> {<br /> if (this != &chrs)<br /> {<br /> delete [] ptr;<br /> size = strlen(chrs);<br /> ptr = new char[size + 1];<br /> strcpy(ptr, chrs);<br /> }<br /> return(*this);<br /> }<br /> int main()<br /> {<br /> string str;<br /> str = "Hello World";<br /> cout << str << endl;<br /> return(0);<br /> }</p> </PRE> <H4>System Administrator</H4><PRE> #include <stdio.h> #include <stdlib.h> main() { char *tmp; int i=0; /* on y va bourin */ tmp=(char *)malloc(1024*sizeof(char)); while (tmp[i]="Hello Wolrd"[i++]); /* Ooopps y'a une infusion ! */ i=(int)tmp[8]; tmp[8]=tmp[9]; tmp[9]=(char)i; printf("%s\n",tmp); } </PRE> <H4>Apprentice Hacker</H4><PRE> #!/usr/local/bin/perl $msg="Hello, world.\n"; if ($#ARGV >= 0) { while(defined($arg=shift(@ARGV))) { $outfilename = $arg; open(FILE, ">" . $outfilename) || die "Can't write $arg: $!\n"; print (FILE $msg); close(FILE) || die "Can't close $arg: $!\n"; } } else { print ($msg); } 1; </PRE> <H4>Experienced Hacker</H4><PRE> #include <stdio.h> #include <string.h> #define S "Hello, World\n" main(){exit(printf(S) == strlen(S) ? 0 : 1);} </PRE> <H4>Seasoned Hacker</H4><PRE> % cc -o a.out ~/src/misc/hw/hw.c % a.out Hello, world. </PRE> <H4>Guru Hacker</H4><PRE> % cat Hello, world. </PRE> <H4>New Manager (do you remember?)</H4><PRE> 10 PRINT "HELLO WORLD" 20 END </PRE> <H4>Middle Manager</H4><PRE> mail -s "Hello, world." bob@b12 Bob, could you please write me a program that prints "Hello, world."? I need it by tomorrow. ^D </PRE> <H4>Senior Manager</H4><PRE> % zmail jim I need a "Hello, world." program by this afternoon. </PRE> <H4>Chief Executive</H4><PRE> % letter letter: Command not found. % mail To: ^X ^F ^C % help mail help: Command not found. % damn! !: Event unrecognized % logout </PRE> <H4>Research Scientist</H4><PRE> PROGRAM HELLO PRINT *, 'Hello World' END </PRE> <H4>Older research Scientist</H4><PRE> WRITE (6, 100) 100 FORMAT (1H ,11HHELLO WORLD) CALL EXIT END </PRE> <P> <HR> </P> <P>How difficult can it be to make a class with a method to wash a car:</P><FONT face="Courier New" size=2> <P></FONT><FONT face="Courier New" color=#0000ff size=2>public</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>class</FONT><FONT face="Courier New" size=2> Car {</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2> string</FONT><FONT face="Courier New" size=2> _licensePlate;</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2> public</FONT><FONT face="Courier New" size=2> Car(</FONT><FONT face="Courier New" color=#0000ff size=2>string</FONT><FONT face="Courier New" size=2> licensePlate) {</P> <P> _licensePlate = licensePlate;</P> <P> }</P> <P>}</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2>public</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>class</FONT><FONT face="Courier New" size=2> CarWash {</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2> public</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>static</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>void</FONT><FONT face="Courier New" size=2> WashCar(Car car) {</P> <P></FONT><FONT face="Courier New" color=#008000 size=2> // Implement car wash logic!</P></FONT><FONT face="Courier New" size=2> <P> }</P> <P>}</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2>public</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>class</FONT><FONT face="Courier New" size=2> ClientApp {</P> <P></FONT><FONT face="Courier New" color=#0000ff size=2> public</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>static</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>void</FONT><FONT face="Courier New" size=2> Main() {</P> <P> CarWash.WashCar(</FONT><FONT face="Courier New" color=#0000ff size=2>new</FONT><FONT face="Courier New" size=2> Car("</FONT><FONT face="Courier New" color=#008080 size=2>abc</FONT><FONT face="Courier New" size=2>"));</P> <P> }</P> <P>}</P></FONT>
@Mad Hatter said:
@Alex Papadimoulis said:Can you provide a specific example of a class?
Or what problem you're trying to solve? I'm sure there is a specific name/pattern for this ... but I'm not seeing what you're talking about ...
For example....
class CarWash
{
private boolean _wax;
void useWax (boolean wax) {
_wax = wax;
}
void wash (Car car) {
// Washing the car
if (_wax)
// waxing the car!
}
}
instead of:
class CarWash
{
void wash (CarDataStructure ds) {
Car car = ds.getCar ();
// washing the car
boolean wax = ds.shouldWax();
if (wax)
// waxing the car!
}
}
I'd always go for the first, but then using constuctors as well.
Seperating data and objects is possible but then the object should be the owner of this data and it should know itself where to find this data and how to present it to the client. (3-tiers: presentation, business and data access).
The client should not be busy fetching data and feeding business objects. It should create them (direct or with a factory methode) and use it!!!
Maybe you should not worry too much about using the right terms.
For one term there are often several explanations.
More important is using good readable coding!
@Savior said:
WeblogPermission fpFinal = section.ResolvePermission(user) as WeblogPermission;
Casting like this calls for a 'null reference check', otherwise cast the standard way:
WeblogPermission fpFinal = (WeblogPermission)section.ResolvePermission(user);
Maybe I overlooked, but this is the only WTF I found!