Generics Objects

  • Thread starter Thread starter VicToro
  • Start date Start date
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
 
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
 
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
 
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) { ... }
}
 
Back
Top