DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Writing java code the OOPS way?
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2009
Default Writing java code the OOPS way? - 05-29-2009, 08:18 AM

Hi,

I and my friend yesterday were discussing about a project in his company that was doomed.

The reason given by the client for the decision was that " Your developers have coded java in a procedural way and not in an Object oriented way".

I am not so clear on this. Could someone tell with few examples(or some URLs) the difference between Procedural Java and OOPS style java?


Thanks
Venu
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2009
Location: Taipei
Send a message via MSN to Ovda8aO
Default 05-29-2009, 11:51 PM

Can Tell the OOPS with Linux operation ? What's up to OOPS ? The subjects to OOPS data structure of here doing.
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2009
Default 06-01-2009, 02:18 AM

not able to understand what you are trying to convey
Reply With Quote
  (#4 (permalink)) Old
Moderator
 
jwenting's Avatar
 
Posts: 99
Thanks: 0
Thanked 8 Times in 8 Posts
Join Date: Feb 2008
Send a message via MSN to jwenting
Default 06-02-2009, 01:35 AM

which shows clearly that your customer was correct in his assertion that the project is doomed.
Utter incompetence of the people manning the project (which your ignorance indicates beyond doubt) is a guarantee of that.
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 11
Thanks: 0
Thanked 2 Times in 2 Posts
Join Date: May 2009
Default 06-03-2009, 04:43 AM

Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

Lesson: Interfaces and Inheritance (The Java™ Tutorials > Learning the Java Language)

This should give you an idea about OOP in Java...
Reply With Quote
  (#6 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2009
Default 06-03-2009, 07:56 PM

OOP is more than knowing about classes, interfaces, inheritance and polymorphism. It's also about building your system in an object oriented way and frankly, it takes some experience and time to "get it."

Some signs that you built procedural code using Java:
  1. Lots of "util" or "helper" classes
  2. Lots of static methods and fields in your code
  3. Lots of switch statements
  4. Lots of singletons (a.k.a., global variables in disguise)

And these are just a few.
Reply With Quote
  (#7 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2009
Default 06-03-2009, 08:10 PM

@jwenting: I don't believe venuwin said it was at *his* company, so what you refer to as his 'ignorance' has no bearing on the project he was talking about. Besides, if it troubles you so, why not provide some examples? Might be a tad more helpful

@venuwin: Some tell-tale proceduralisms would be lots of 'instanceof' checks in the code (e.g. the switch statements santoro63 talks about). This indicates the developer is not taking advantage of Java's OO features such as inheritance, which would allow the JVM to invoke ('dispatch') the appropriate operations on objects automatically, as opposed to having the code explicitly check for object types and calling. E.g.:

Code:
// procedural (not so pretty)
Animal animal = new Mouse();
if (animal instanceof Mouse) {
  System.out.println("cheese");
} else if (animal instanceof Cat) {
  System.out.println("catnip");
}
As opposed to:

Code:
class Animal {
  public abstract String getFood();
}

class Mouse extends Animal {
  @Override
  public void getFood() { System.out.println("cheese"); }
}

class Cat extends Animal {
  @Override
  public void getFood() { System.out.println("catnip"); }
}

// now the JVM can automatically decide what
// method to invoke 
Animal animal = new Cat();
animal.getFood();
Google for OO, instanceof, dispatch, etc. Hope this helps!

Toedeloe,
Erik

Last edited by eriksensei; 06-03-2009 at 08:29 PM.
Reply With Quote
  (#8 (permalink)) Old
Member
 
Posts: 11
Thanks: 0
Thanked 2 Times in 2 Posts
Join Date: May 2009
Default 06-04-2009, 04:18 AM

@Santaro63 Of course OOP is not only about classes, interfaces and so on, and I agree with you that it takes a lot of time to understand the really important things... I just wanted to provide a good reference to start with...
Reply With Quote
  (#9 (permalink)) Old
Member
 
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Sep 2009
Default 09-21-2009, 03:24 AM

It's also about building your system in an object oriented way and frankly, it takes some experience and time to "get it."
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
example code for Java I/O second edition JBengonsen Java 1 06-02-2009 01:37 AM
Java 5 Source Code kirenpillay Java 1 11-13-2008 06:19 PM
writing java script ratha Ajax & Javascript 0 11-11-2008 05:48 AM
Interpret C code in java Code sammyac Java 0 10-15-2008 09:17 AM
Java API to do Zip Code Lookup jhough76 Java 0 03-10-2008 09:09 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com