Object Oriented Design in Java

I am an RPGIV programmer trying to switch to Java. I have some experience with Java syntax and basic fundamentals. My question pertains to OOP specifically. I am trying to write a version of the old C-robots program in java. It was an AI simulation project written in C years ago where you could modify the actual AI code and then implement it to test results with 3 other robots with different AI. My question is this: When trying to break down the methods for an interface client to control the robot objects, how do you know what messages that particular client should take care of. In a GUI version I imagine that all the interface client would need to know is basically getPosition() and getDamage() for the display. Then the robot objects would handle all of the other methods including moving(), scanning() and shooting() just to keep it simple. (many more methods are needed, I know). i guess in a nutshell i am trying to determine good program design when it comes to object responsibility. how much responsibility should the interface have as opposed to the other. thank you

Hi! Welcome to Java. You have a rather broad-based question which primarily deals with good o-o design.
I'd recommend reading the chapters relating to o-o design from Bruce Eckel's "Thinking In Java". The electronic edition of the book is available for free download at http://www.bruceeckel.com.
Now, regarding the interface client, you need to determine what other entities it will interact with and from that determine what methods it must have in order to permit those interactions. That's a rather short way of putting it, I know. However, hopefully that's enough to get you going.
Hope this helps! Feel free to ask if something's not too clear.
Cheers!

Similar Messages

  • Exception Handling in Object Oriented Design

    I am developing a huge web based project using Object Oriented design and java,srvlets ,jsp etc ,I am using 3-tier archtecture.I dont understand,how i should handle exceptions in my project.ie.If there is some exception in the base modules how should it be handled.What kind of excpetion Structure should i use,How many exception classes should be made etc,
    Can someone help me in this regard

    A couple things I have found to be good practices for exception handling in an n-tier architecture:
    1. Don't expose all the internal exceptions of a tier to the client of the tier. Create a more useful, descriptive set of exceptions (or use the appropriate predefined exceptions) to throw up to the client.
    For example, on one project, we are doing database access among other things in the "service" tier, which is accessed by the web tier. We catch the SQLExceptions, PersistenceExceptions (a custom exception), and others, and throw a more useful exception that the client will know how to handle such as a NoMeasurementResultsException if the client asks for measurement results when we have none.
    2. Chain your exceptions and/or log the root cause in the tier that re-throws a different exception. There is nothing more aggravating than not knowing why, when you are debugging a problem, you are getting a NoMeasurementResultsException when you know that there ARE results in the database.
    Hope these ideas help in your design.
    Cheers,
    Colin

  • Good book on Object Oriented Design?

    Can you recommend a good book on Object Oriented Design with lots of practical examples? I already have:
    http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1238324375&sr=8-1
    But currently I need a book with a more basic approach.

    corlettk wrote:
    I like Thinking In Java... Also: google for "yawmark's list"TIJ is useless, especially for teaching OO design. It teaches (or tries to) Java as a procedural language.

  • Question about Object Oriented Design in Oracle

    Hi everyone,
    Right now I'm updating my oracle skills, years ago without programming (last time with Oracle 7.3 :O)
    Well, if I have to design a new system with this features:
    1.- Using Oracle as DB
    2.- Web enable
    3.- OO Design
    My questions:
    1.- What is the best practice to make database design? E-R + Object Types? I mean is better making the design on Oracle directly or in Java-UML environment?
    2.- I was thinking in programming with Forms, but it works well with OO design?
    3.- If I want to program some web services based, Could I do it with PL/SQL and Jdeveloper?
    please if you know about articles and whitepapers about OO design approach with Oracle let me know!
    Thanks.

    I have been involved in some of these projects that have used Java, C#, VB, C++ etc. as front-end languagaes. I have been able to implement these projects successfully using the following approach:
    1. create a relational model of the database - third-normal form (assuming it is an OLTP application)
    2. Write PL/SQL code (packages and procedures mainly)
    3. Interact with the front-end layer by sending and receiving ref curosors and/or PL/SQL tables
    If you want to use Forms (I am assuming Oracle Forms) then there may not be much need for an OO design. Embeeding SQL in the forms will do most of what you want.
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • Object oriented design problem concerning abstract classes and interfaces

    I have an abstract class (class A) that takes care of database connections. It cannot be made into an interface as other classes extend it and all these other classes require the functionality in the methods it has (i.e. I cannot make all the methods abstract and then make this class an interface).
    I have a class that contains data (Customer class) that I will create from the data I extract from the database. This class will also be created by the User and submitted to the database portion of the program. The Customer class has functionality in its methods which is required by the rest of the program (i.e. I cannot make all the methods abstract and then make this class an interface).
    I have a factory class (CustomerFactory) that extends the Customer class. This has been created to restrict access to the creation and manipulation of Customers.
    I have a class (DatabaseQuery) that extends class A. But now that I have retrieved all of the information that comprises a Customer from the database, I cannot construct a Customer without making reference to UserFactory. But UserFactory is a class that I don't want the database portion of the program to know about.
    What I would like to do is have my DatabaseQuery class extend both Customer class and A class. But they are both classes and Java won't allow that.
    I can't make either of the two classes that I want to make parents of DatabaseQuery into interfaces... so what can I do other than just keep a reference to UserFactory in my DatabaseQuery class?
    Thanks,
    Tim

    >
    What I would like to do is have my DatabaseQuery class
    extend both Customer class and A class. But they are
    both classes and Java won't allow that.
    I can't make either of the two classes that I want to
    make parents of DatabaseQuery into interfaces... so
    what can I do other than just keep a reference to
    UserFactory in my DatabaseQuery class?Just a guess...
    The description sounds a little vague but it sounds like the correct solution would be to refactor everything. The first clue is when I see "database connection" as an "abstract class". The only hierarchy that a database connection might exist in is in a connection pool and even that is probably shaky. It should never be part of data records, which is what your description sounds like.
    That probably isn't what you want to hear.
    The other solution, which is why refactoring is better (and which also makes it apparent why the original design is wrong) is to create an entire other hierarchy that mirrors your current data hierarchy and wraps it. So you now have "Customer", you will now have "Customer" and "DBCustomer". And all the code that currently uses "Customer" will have to start using DBCustomer. Actually it is easier than that since you can simply make the new class be "Customer" and rename the old class to "DBCustomer". Naturally that means the new class will have to have all of the functionality of the old class. Fortunately you can use the old class to do that. (But I would guess that isn't going to be easy.)

  • Theoretical object oriented design question

    Hi,
    I am just getting into the design of some software that will take either one or two numbers and perform identical operations on them. It will then create a label that will be different depending on whether 1 or 2 serial numbers are used.
    In the example it looks like I could make a vehicle class that would contain the serial number, and child classes for car, truck and boat that would define how the sticker was laid out.
    The trouble I am having is that the control for serial number 1 and serial number 2 need to accept any of the three numbers for car truck and boat.
    So I am not sure how to build classes to cover this, and what design pattern would be best.
    So I am looking for ideas.
    I have no real code yet to post, and a lot of the attributes are confidential, which is why I made the simple diagram.

    Search this site for...
    Factory Pattern
    It basiclly uses a case sctructure to to select a Class constant of the proper type.
    Have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Using UML while designing Object oriented design in ABAP

    Hi,
    Is it a general practice in projects to use UML diagrams when you do OO design for a report in ABAP ? Or do people start writing th OO code directly ?
    Reards,
    Rajesh

    Hi Rajesh,
    In my particular case, I use to start writing the code directly after I read and check the documentation. Right now i'm starting to looking around in order to get more experience in OO programming.
    I think that UML is the best option right now, also SAP recommends it. They worked with Rational Software in order to provide an external modeling tool to supports SAP's class.
    Check this link in order to get more information.
    <a href="http://www.sapinsideronline.com/archive/volume_03_(2002)/issue_03_(july-september)/v3i3a11.cfm?session=&promo=iz1321">http://www.sapinsideronline.com/archive/volume_03_(2002)/issue_03_(july-september)/v3i3a11.cfm?session=&promo=iz1321</a>
    Regards,
    Eric

  • Backing Beans Object Oriented Design

    Hello,
    Are there any best practices for using Backing Beans?
    How to make managed beans thread-safe for concurrent requests,
    without compromising on efficiency/speed?
    2. How to enforce the J2EE security with backing-beans?
    3. How to decide the scope of these beans to ensure minimal data-storage
    in session?
    4. How to decide the granularity at which a managed-bean should be used
    for example :
    4.1 One bean-per-component
    4.2 One bean-per-form
    4.3 One bean-per-page
    Also i would like to know how to design managed beans from reusability perspective.
    Regards,
    Smita

    It quite hard to give a brief answer on all your questions.
    I think that you should take into account bean's scope when think about thread safety.
    Request scope bean is single threaded while for session scope you should provide locking mechanism because this bean can be accessed from different threads but only in case when one user simultaneously submit request from multiply browser windows.
    As for security you can use standard security API from within bean through javax.faces.context.ExternalContext
    It is convenient to use one backing bean for some or all components in web form.
    Do not mix form component and business data in one bean. Thus it is good design to have one set of beans for presentation logic and another one for business logic.

  • Object oriented design -book

    Hi
    I'm looking for a good book about oo design. I'm interested in a book showing how to divide real-life probleminto set of classes and methods. Explaining few oo design's methods and so on... I would be really greatful if could recommend me such a kind of book?

    LOL, thank you scarlet for cheering up my ever so
    painful monday morning.Read again. Rene = Frenchman. Scarlet = Limey. I'm
    not him.oops, like i said, "i don't like mondays"
    humming "...I don't like jamaica, i love it ya...".
    I have "Teach yourself the Washing Machine in 21
    Days", but I think there's a misprint somewhere. My
    clothes don't look like 600�C were a good idea... but
    OTOH, maybe I'm doing something wrong. I'm still at
    Day 3 (how to undress before washing the clothes).That misprint sucks.
    But i'm very interested in how you did wash your clothes on 600�C without finishing day 3 first.
    A small hint: I have found the perfect solution so I didn't had to buy that book (I saw it was actually one of the expensive ones in the serie), I got engaged, thinking that would be cheaper.
    I couldn't be more off on that one.

  • Question about Object-Orientated design for GUI'S

    Hi everyone,
    I am designing a simple GUI, which basically enables a user to input and retreive data.
    So I have a prototype GUI lets call it "myFrame". It extends JFrame, and I place my components onto myFrame, JButtons, JTextfields etc. I have the GUI set up the way I want it, so I move onto implementing the actionListeners.
    The problem is that one of the components I have placed on myFrame has its own mouseListener. Its a type of Icon (i created in a seperate class)which extends JComponent, and I thought it would be sensible to give it control of its own mouseListener, so it cuts down on the code within the myFrame class.
    But I now realise that I can't alter the other components on myFrame from within the mouseListener in the icon class. I know the icon class doesn't have access to any of myFrames methods or instance fields, so how do I correctly implement this. Surely the answer isn't to bung all the code together into one class?
    visually what I have so far looks like this
    SERVER <---Requests---> myFrame --------> IconList ---------> Icon
    the IconList class looks up a server to update its array of Icons[]. But when one individual Icon is clicked on myFrame, i want its mouseListener to load some of its values onto myFrame's GUI components.
    I hope I'm making myself clear, im sorry if this seems like a muddled incoherent question, but any advice would be great. I only need to be shown the correct way to design, and then i carry on coding happily. If this kind of design is way off, please let me know!!
    Thanks

    You can absolutely do work on the frame from the mouse listener--It just needs an instance. i.e.
    public class MyMouseListener implements MouseListener {
      private MyFrame frame;
      public MyMouseListener(MyFrame frame) {
        this.frame = frame;
    }Does that make sense?
    That said, what you'll see more often is a Model-View-Control approach, wherein the Control (the mouse listener in your case) effects the Model and the Model notifies the View to update its display, rather than the Control updating the view directly. That's the extreme overview version, lots of good hits on google if you're interested beyond that

  • Proper object oriented design for factory class

    I have a factory class (UserFactory) it is capable of creating two types of classes (Customer and Employee) that extend User. User is an abstract class.
    At present any class could create a Customer of an Employee.
    How do I restrict access to the constructors of Customer and Employee only to UserFactory?
    I don't want to make both of these classes interfaces (in which case I could just have UserFactory implement both of them).
    Here is an example of how they are set up at present:
    public abstract class User {
    public class Customer extends User{
    public Customer{
    public class Employee extends User {
    public Employee {
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    Oh and I don't want to create two separate factory classes for Employee and Customer. In C++ there is a concept of friend classes that would have worked nicely in this case.
    Thanks for any and all suggestions,
    Tim

    So correct me if I'm wrong but your suggestion would be something along the lines of:
    public abstract class User {
    public class Customer extends User{
    protected Customer(){
    public class Employee extends User {
    protected Employee (){
    public class UserFactory ???? {
    private static UserFactory c_userFactory = null;
    private UserFactory (){
    public UserFactory getInstance(){
    //private clone method too
    public Customer createCustomer(){
    public Employee createEmployee(){
    public class AccessForCustomer extends Customer {
    public class AccessForEmployee extends Employee {
    Is the above about what you were talking about? I haven't used inner classes before, so I'm a bit curious. Does this mean no class other than UserFactory or derivatives thereof can access the two classes AccessForCustomer and AccessForEmployee?
    Thanks,
    Tim

  • Anyone recommends a good book for object oriented programming

    I am a college student in computer engineering (Software) and have been programming using Java for over a year. I have become really interested in the design of softwares and the "beauty" of object oriented programming, and thus would like to advance my knowledge about the topic (my university offers an advanced oop class but I would have to wait another 6 months to take it). So my question is, could you recommend me any book that covers the subject of object oriented programming extensively? (I have learned most of the oop I know from "An Introduction to Programming and Object Oriented Design Using Java" by Nino and Hosch.
    Thanks in advance

    Some years ago I remember cutting my teeth on OOP using an excellent book by Grady Booch. If it's still in print and has been updated, it may be worth a look. Again it was decent. Also consider picking up a book on design patterns. Good luck.
    Edit: I found it, it's called "Object-Oriented Analysis and Design with Applications", and it's in its third edition. You can find it here on Amazon.
    Edited by: Encephalopathic on Apr 22, 2008 2:48 PM

  • Anyone recommends a good book for object oriented programming (advanced)

    I am a college student in computer engineering (Software) and have been programming using Java for over a year. I have become really interested in the design of softwares and the "beauty" of object oriented programming, and thus would like to advance my knowledge about the topic (my university offers an advanced oop class but I would have to wait another 6 months to take it). So my question is, could you recommend me any book that covers the subject of object oriented programming extensively? (I have learned most of the oop I know from "An Introduction to Programming and Object Oriented Design Using Java" by Nino and Hosch.
    Thanks in advance

    jwenting wrote:
    I never tire of pushing ["Agile Software Development, Principles, Patterns, and Practices "|http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445] by Robert Martin.
    You probably meant [Agile Software Development, Principles, Patterns, and Practices|http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445] ;-)
    Remember, quotes in link names break the forum ...

  • Java is a Partially Object-Oriented Programming (True/False)

    Hi everybody,
    Many of them saying that Java is not purely Object-Oriented Programming.
    I am very much confusing on that, so please help me to confirm that "Java is a Partially Object-Oriented Programming Language".

    JAVA_NV wrote:
    gopivista wrote:
    Hi everybody,
    Many of them saying that Java is not purely Object-Oriented Programming.
    I am very much confusing on that, so please help me to confirm that "Java is a Partially Object-Oriented Programming Language".Java is not purely Object-Oriented Programming,for this two reasons are there
    one is we cant create Objects to the primitive data types and there is no multiple Inheritance concept .While there are many definitions of "purely object oriented," and no on widely accepted standard, I've never heard one that requires multiple inheritance. That would NOT be a reason why Java is not fully OO.

  • How do YOU name classes? (object oriented programming)

    I am in the process of learning advanced object oriented design, and I am trying to use it in my personal programming project. I'm having a hard time implementing all of the classes I want for it because I can't think of what to call them.
    So, my question is, in object oriented design, how do you name the implementations and abstractions that you make?
    In other words, "implementations" can be thought of as "classes", and "abstractions" as "interfaces" in Java or "pure abstract classes" in C++. How do you name the classes and interfaces you make?
    For example, do you use prefixes or suffixes on your names, such as "I" for "interface" or "Impl" for "implementation"? Do you add "-able" to the end of the name of an abstraction, such as "Decoratable"? Can you always think of simple logical names for all of your classes, and it just has never been a problem for you?
    As an example of how the number of classes quickly grows, the Decorator Pattern will use at least five classes. I have no idea what I would name those in a programming project.

    drcouzelis wrote:
    Trent wrote:Theoretically speaking, you'll have multiple implementations of the Window interface, which will have their own unique names suggested by their respective purposes.  If not, then Window and its implementation should probably be merged into a single class.
    Thank you for bringing that up.
    How about this: The name of the implementation class will be HOW its implemented followed by the name of the interface.
    A "Window" interface would have implementations such as "AllegroWindow", "GTKWindow", or "HaikuWindow".
    In a video game, a "Character" interface would have implementations such as "GeneralCharacter", "ControllableCharacter", "PlayableCharacter", or "EnemyCharacter".
    Does that sound like a good idea?
    Indeed, classes are more specific than interfaces, subclasses are more specific as their superclasses... This should be reflected in their names, the name of a class that implements an interface should somehow make clear exactly what it is (e.g. what kind window). If you have a kind of window (for instance) that is really _just_ a window, nothing else, than the interface should become this class and the implementing classes should become subclasses.

Maybe you are looking for