Generics Objects

V

VicToro

Hi all,

I created a Class defined as:

public class GenericDataAccess<T> : DataAccessObject<T> where T :
DBObject

This is my base class. I reuse it in every project. Now, in a
particular project I have another class:

public class DataAccess<T>: GenericDataAccess<T> where T:DBObject

This last class have methods as:

public static List<T> getAll()
public static T getOne()
....

I also have one method called:

public static bool IsLogin(string userName, string password)

I would like to make this method accesible just for one class, that is
called User and inherits from DBObject.
But I do not want it to be accesible for the rest of the classes that
inherit from DBObject (i.e. Role, Apartment...)

Any idea of how can I implement my idea?

Thanks in advance
 
P

pamela fluente

Hi all,

I created a Class defined as:

public class GenericDataAccess<T> : DataAccessObject<T> where T :
DBObject

This is my base class. I reuse it in every project. Now, in a
particular project I have another class:

public class DataAccess<T>: GenericDataAccess<T> where T:DBObject

This last class have methods as:

public static List<T> getAll()
public static T getOne()
...

I also have one method called:

public static bool IsLogin(string userName, string password)

I would like to make this method accesible just for one class, that is
called User and inherits from DBObject.
But I do not want it to be accesible for the rest of the classes that
inherit from DBObject (i.e. Role, Apartment...)

Any idea of how can I implement my idea?

Hello Vic,
your question raises the doubt you are correctly modeling your
objects.

If a derived class does not need a parental field or property then you
are *probably* using wrongly the concept of inheritance.

It makes sense that D inherits from P only if D "is a" P.

When one needs etherogeneous objects to share properties I find
convenient to use interfaces.

Anyway I'd like to hear others' opinions about that.

-Pam
 
K

Kevin Spencer

If you only want the method to be accessible to one derived class, define it
in the derived class.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
B

Ben Voigt

VicToro said:
Hi all,

I created a Class defined as:

public class GenericDataAccess<T> : DataAccessObject<T> where T :
DBObject

This is my base class. I reuse it in every project. Now, in a
particular project I have another class:

public class DataAccess<T>: GenericDataAccess<T> where T:DBObject

This last class have methods as:

public static List<T> getAll()
public static T getOne()
...

I also have one method called:

public static bool IsLogin(string userName, string password)

I would like to make this method accesible just for one class, that is
called User and inherits from DBObject.
But I do not want it to be accesible for the rest of the classes that
inherit from DBObject (i.e. Role, Apartment...)

Any idea of how can I implement my idea?


public class UserDataAccess : DataAccess<User>
{
public static bool IsLogin(string userName, string password) { ... }
}
 

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

Similar Threads

Polymorphic generics 4
Help with generics 2
Generics and static members 1
Generics; OO 4
Generics Issue with Simple Factory 1
Generics and multi-level inheritance 2
about using compare with generics 8
Generics 7

Top