Good coding style

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!
[292 byte] By [Wenxiaoa] at [2007-10-2 13:09:58]
# 1

> 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/

dubwaia at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> 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();

}

}

CeciNEstPasUnProgrammeura at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
my eyes...
tsitha at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

> > 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... ;)

MrPicklesa at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 5

> > > 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.

mlka at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
http://en.wikipedia.org/wiki/God_object http://www.answers.com/topic/anti-patterngod method perhaps!
mchan0a at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> 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?

%

duffymoa at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...
# 8

> 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

Drake_Duna at 2007-7-13 10:36:54 > top of Java-index,Other Topics,Patterns & OO Design...