Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-04-2010
Member
 
Join Date: Apr 2010
Posts: 1
UML to Java question

I have a UML that I have to convert to Java code. The only thing I cannot figure out is how to call method op2() in class B from classes C and D. If I create an object of class B, then the whole program goes into an infinite loop. And I cannot even make the method op2() a class method. Can anyone tell me where I need to correct the code?



Code:
public class B extends A {
  public static void main(String args[]) {
    new B();
  }
  private C c;
  private D d;
  public B() {
    System.out.println("B()");
    c = new C(this);     // 1:
    d = new D(this);     // 2:
    c.op3(d);            // 3:
    d.op4(c);            // 4:
  }
  public void op2() {
    System.out.println("B.op2()");
    op1();               // 3.1.1.1:  and  4.1.1.1:
  }

}

class A{
    public void op1() {
	System.out.println("A.op1()");
	}
}


class C {
	private B b;
	private D d;
	public C(B b) {
	System.out.println("C()");
	}

	public void op3(D d) {
	System.out.println("C.op3()");
        d.op5();
	}

	public void op5() {
        System.out.println("C.op5()");
	b.op2(); //erroneous part
	}
}

class D {
	private B b;
	private C c;
	public D(B b) {
	System.out.println("D()");
	}

	public void op4(C c) {
	System.out.println("D.op4()");
        c.op5();
	}

	public void op5() {
	System.out.println("D.op5()");
        b.op2();  //erroneous part
        }
}
Reply With Quote
  #2  
Old 20-04-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: UML to Java question

Hello,
What exactly are you trying to do in your classes. The op2() method is in class B. So, if you need to use this method in class C and class D then you will need to extend class C and class D with class B. I think this is the solution for it. Also, if you need some other way round then you can also you class B as an interface so that it can be called by class C and class D at the same time, that is multiple inheritance.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "UML to Java question"
Thread Thread Starter Forum Replies Last Post
Basic Java question colby02184 Software Development 2 11-11-2011 05:08 PM
Question to Hibernate in Java Development Taarank Software Development 5 29-07-2010 01:51 AM
Java - question on enum ISAIAH Software Development 5 02-03-2010 10:50 AM
Java math question Daren Software Development 2 02-09-2009 06:33 PM
Frequently asked Core Java Question for Inteview Eaton Education Career and Job Discussions 2 05-11-2008 01:54 PM


All times are GMT +5.5. The time now is 05:51 PM.