Thanks Mihai, I forgot I can assign the reference of the interface type
with the object of a class implemented the imterface.

On Wed, Apr 14, 2010 at 1:16 PM, Mihai DINCA <[email protected]> wrote:

> Hi Kc,
>
> I don't know which one of the homeworks you are talking. The code seems
> correct to me. Just one observation, you can define in the Person class a
> member "AdressInterface address;" and have in the constructor:
>
>     // Constructor with arguments
>     Person(int cashSaving,
>             int retirementFund,
>             String firstName,
>             String lastName,
>             *AddressInterface* address) {
>         this.cashSaving = cashSaving;
>         this.retirementFund = retirementFund;
>         this.firstName = firstName;
>         this.lastName = lastName;
>         this.address = address;
>     }
>
> In this way, the Person class is not dependent on the implementation
> AddressImpl, but it is still possible to call the constructor like this:
>
> Person person = new Person( 100, 200, "First", "Last", *new AddressImpl(
> ...)*);
>
> For e.g., let's assume that the Person class is written by your team, but
> the AddressImpl by another team. You have to do your job, but the other team
> didn't finish theirs, so you cannot create your Person class without having
> error signs from NetBeans. One way to do it is to agree on the interface
> with the other team. Write together the interface. Then you can work to your
> Person class just referencing the interface, without any error, and the
> other team can create AddressImpl just implementing the AddressInterface.
> (Of course, AddressImpl must be ready before someone can test the whole).
>
> Hope it helps
> mihai
>
>
> kc a écrit :
>
> Hi,
>
> I am not sure this is the right way to do the workwork, please advise.
>
> 1.  To implement MyOwnInterfac, I will need to create a reference
> variable <address> of AddressImpl type in Person class, so i can use
> it in the constructor and implement the getAddress method
>
>     // Constructor with arguments
>     Person(int cashSaving,
>             int retirementFund,
>             String firstName,
>             String lastName,
>             AddressImpl address) {
>         this.cashSaving = cashSaving;
>         this.retirementFund = retirementFund;
>         this.firstName = firstName;
>         this.lastName = lastName;
>         this.address = address;
>     }
>
>     public AddressInterface getAddress() {
>         return address;
>     }
>
>
>
> 2. I will also need to create a reference variable <address> of
> AddressImpl type  in order to create object instance of Person class
>
>         AddressImpl address = new AddressImpl("Malaysia", "Jalan
> Ismail", 30);
>         Person person1 = new Person(10000, 20000, "Sang", "Shin",
> address);
>
> Regards
> KC
>
>
>
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to