Title: Question about Java Bean

Hi guys,

I have a little question to clear up my understanding about Java bean. I have a project to create a mail application and I wanted to create a java bean for the message currently opened so that if user wants to reply or forward a message, they can just get the message from the bean and start sending right away.

Now, my confusion is... I always thought that JavaBean is only behaving like a data storage with just a bunch of set and get methods to set and to retrieve the data needed. I always thought that, although you can, it is not appropriate to put the "logic" for sending the message in the bean itself.

I have also heard from some people, that beans can have a logic in it so that in the case of my mail application, instead of I create another class that will read the mail data from the bean perform the sending logic, I can actually put the send logic in the bean.

My only question is that if we do such thing, putting the logic in a bean, and somehow we have a huge logic and that many people instantiated the bean, wouldn't it be overheads for the server?

Please help me clarify about Java Beans. I tried to go online about this, but none of them have a clear explanation for me. Maybe if you can give me some sample code skeleton, I can understand better.

Thanks in advance.
Rendra Basuki

PS: Here is the difference in opinion of java bean that I mentioned above, which one is more correct?

My view:
MailMessageBean.java

public class MailMessageBean
{
        setAddress()
        setFrom()
        getAddress()
        getFrom()

        ....... etc
}

public class MailSendEngine
{
        String host = "";

        public void setHost(String h) host = h;
       
        public void send(MailMessageBean)
        {
                //Perform the send process here and get all the needed data from the bean.
        }
}



Other people's view:
public class MailMessageBean
{
        setAddress()
        setFrom()
        getAddress()
        getFrom()


        ....... etc
}

Reply via email to