extending of adding method?

G

Gerardo Herzig

Hi all. I have a question about design. The general question would be:
Where is the line beteween extending a class and adding new methods to
that class?

And the particular case im involved is:

I have a class (say USERCLASS) who implements a user interface. One of
his methods is called `login'. Later on i got the order of implementing
a `single login', which off course means a single user cant login if a
session is already started for that user. Extending comes to my mind at
first (it works good, actually). But now im thinikng if there some
problem in adding a method to the USERCLASS class named single_login(),
who will take care of applying the rules of single sign on.

Which one you guys will pick up? USERCLASS().single_login() or
SINGLELOGINUSERCLASS().login()


Thanks for your oppinions!
Gerardo
 
B

Bjoern Schliessmann

Gerardo said:
Hi all. I have a question about design. The general question would
be: Where is the line beteween extending a class and adding new
methods to that class?

What do you mean by "extending"? The Java "extends", which is really
inheritance?
And the particular case im involved is:

I have a class (say USERCLASS) who implements a user interface.
One of his methods is called `login'. Later on i got the order of
implementing a `single login', which off course means a single
user cant login if a session is already started for that user.
Extending comes to my mind at first (it works good, actually). But
now im thinikng if there some problem in adding a method to the
USERCLASS class named single_login(), who will take care of
applying the rules of single sign on.

Which one you guys will pick up? USERCLASS().single_login() or
SINGLELOGINUSERCLASS().login()

Depends. Inheritance is, IMHO, only good if it makes code reusal
and/or maintainability easier. I've once read that inheritance
often only is wise in "is a" relationships, e. g. "car is a
vehicle", which means class "car" should inherit from
class "vehicle".

Regards,


Björn
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top