> I'm new to OO design. I find it easy to write all the
> procedures inside the main function:
>
> public static void main(String[] args) {
>
> }
>
> which I do not think is a good coding style. Could
> anybody tell me the disadvantages of it and how to
> modify it? Thanks in advance!
Where to start? This is definitely not good design nor is it OO.
Start here maybe:
http://java.sun.com/docs/books/tutorial/java/concepts/
> which I do not think is a good coding style. Could
> anybody tell me the disadvantages of it and how to
> modify it? Thanks in advance!
The disadvantage is this:
public static void main(String[] args) {
len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
}
len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
} len_s1 = s1.count;
len_s2 = s2.count;
this.count = len_s1 + len_s2;
this.value = new char[this.count];
System.arraycopy(s1.value, s1.offset, this.value, this.offset, len_s1);
System.arraycopy(s2.value, s2.offset, this.value, this.offset+len_s1, len_s2);
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
}
}
> > which I do not think is a good coding style. Could
> > anybody tell me the disadvantages of it and how to
> > modify it? Thanks in advance!
>
> The disadvantage is this:
>
> public static void main(String[] args) {
> len_s1 = s1.count;
> len_s2 = s2.count;
> this.count = len_s1 + len_s2;
> this.value = new char[this.count];
> System.arraycopy(s1.value, s1.offset,
> }
> }
Is that really such a bad thing though... ;)
> > > which I do not think is a good coding style.
> Could
> > > anybody tell me the disadvantages of it and how
> to
> > > modify it? Thanks in advance!
> >
> > The disadvantage is this:
> >
> > public static void main(String[] args) {
> > len_s1 = s1.count;
> > len_s2 = s2.count;
> > this.count = len_s1 + len_s2;
> > this.value = new char[this.count];
> > System.arraycopy(s1.value, s1.offset,
> > }
> > }
>
> Is that really such a bad thing though... ;)
Not at all, but I am a little worried about how Rene got hold of my code.
> I'm new to OO design. I find it easy to write all the
> procedures inside the main function:
>
> public static void main(String[] args) {
>
> }
>
> which I do not think is a good coding style. Could
> anybody tell me the disadvantages of it and how to
> modify it? Thanks in advance!
Ask yourself: How will other classes use this functionality if it's all locked up in a main method that runs on the command line?
How will you pass anything in other than a String array?
%
> Ask yourself: How will other classes use this
> functionality if it's all locked up in a main method
> that runs on the command line?
>
> How will you pass anything in other than a String
> array?
Also, how will you look at yourself in the mirror? How will you sleep at night?
Drake