This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getClass() from another class

 
Matthew Peters
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. Great to see a greenhorn friendly java site! So many forums seem to neglect the beginners...

Anyway, my problem is this:
- I need to return Customer from Bank where Customer is another class
- I then need to access a toString() method within Customer (eg Bank.getCustomer().toString();)

public class Bank
{
...
public Customer getCustomer()
{
return ???;
}
...
}

public class Customer
{
...
public String toString()
{
...
return sbuilder.toString();
}
}

Any help would be much appreciated! Cheers. Ollie
 
Henry Wong
author
Marshal
Pie
Posts: 20990
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Well, that is completely up to you -- it's your application. Are you returning a favorite customer? Are you returning the last customer that came into the bank? Are you returning the customer based on a transaction? or a session that the caller is holding? etc. It's purely an implementation detail.

Now, of course, you can also do this.



But I highly doubt you want that... Banks shouldn't be able to just create a customer, so it won't make sense for your program to do that...

Henry
 
Matthew Peters
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually just want to return the customer (this is a very simple model at this stage)... doesn't have to be a favorite or last customer...

Any clues on how to do this?
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ollie monch wrote:Any clues on how to do this?
Read Henry Wong's post on this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic