No interface when the constructor mandatorily requires arguments??

Q

qazmlp1209

Requirement:
- A class has 4 members. 2 of these members are must to constitute the
concrete object.
The other 2 are optional.

What I thought of for defining interfaces to the users are:
- Provide only one version of constructor taking the 2 mandatory
members as arguments.
- Provide setters for the other 2 members.
- Provide getters for all the 4 members.

In general, it is a good style to introduce an 'interface' with all the
methods that the users require for. But unfortunately, this does not
seem to work for my above-mentioned requirements. This is due to the
reason that the class implementing the interface should provide a
constructor with empty arguments.

Can anybody suggest the best approach for such cases?
 
R

René Beltman

Write an abstract class. In this class you can set the constructor sorts.

Greetings,

René
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

(e-mail address removed) schreef:
Requirement:
- A class has 4 members. 2 of these members are must to constitute the
concrete object.
The other 2 are optional.

What I thought of for defining interfaces to the users are:
- Provide only one version of constructor taking the 2 mandatory
members as arguments.
- Provide setters for the other 2 members.
- Provide getters for all the 4 members.

In general, it is a good style to introduce an 'interface' with all the
methods that the users require for. But unfortunately, this does not
seem to work for my above-mentioned requirements. This is due to the
reason that the class implementing the interface should provide a
constructor with empty arguments.

Why? Is this some restriction you impose on yourself? Anyway, you
cannot write an interface for constructors, so this won?t work anyway.

H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEDEQye+7xMGD3itQRArr0AJ4p2TKm32BdMgOnA+SmoJYqYszVFgCfRSdt
GfjVejeqbsr8msHPQTjSjZY=
=onPK
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top