So obviously you cannot override static methods but my question is if there might be some way around it?
I am building a base class that will wrap the CSLA BusinessBase and handle the CRUD in a uniform way. Then my classes will all inherit from this base and set their own properties so that the base class knows what properties each object has.
The base class needs to be able to define the CanAdd, CanEdit, CanGet, etc. so that each object can have it's own permissions. These functions are static as they are called by the factory methods (which are obviously static).
Any ideas on getting around this issue without having to move all the test logic up to each of the inheriting classes?
Thanks,
Michael
Wbmstrmjb:So obviously you cannot override static methods but my question is if there might be some way around it?
I am building a base class that will wrap the CSLA BusinessBase and handle the CRUD in a uniform way. Then my classes will all inherit from this base and set their own properties so that the base class knows what properties each object has.
The base class needs to be able to define the CanAdd, CanEdit, CanGet, etc. so that each object can have it's own permissions. These functions are static as they are called by the factory methods (which are obviously static).
Any ideas on getting around this issue without having to move all the test logic up to each of the inheriting classes?
Thanks,
Michael
Thank you so much for your responses. I guess I am having a hard time with grasping the suggestion by Bayu. The way I read it, I'd put all of my checking in the base class and therefore it would need to know about all the different possible types of objects I may create that inherit that class (obviously I could just have it load a collection of objects from a DB and then it would "know" based on the DB).
But what if the objects don't all "work" that way? Can I not write custom CanAdd, Can Edit, etc. functions in the derived classes that can "override" the base functionality? My creative juices have run out.
Thanks,
Mike
ajj3085:I wouldn't recommend this method, as using new breaks some OO principals pretty badly.
ajj3085:Not too familar with VB, but I believe that's correct. new in C# allows you to 'override' anything, marked virtual or not, and allows you to change the method signature as well. I think that's what Shadows does, correct?
Wbmstrmjb:So obviously you cannot override static methods but my question is if there might be some way around it?
I am building a base class that will wrap the CSLA BusinessBase and handle the CRUD in a uniform way. Then my classes will all inherit from this base and set their own properties so that the base class knows what properties each object has.
The base class needs to be able to define the CanAdd, CanEdit, CanGet, etc. so that each object can have it's own permissions. These functions are static as they are called by the factory methods (which are obviously static).
Any ideas on getting around this issue without having to move all the test logic up to each of the inheriting classes?
Thanks,
Michael
A couple of other options.1. Do they really have to be static/shared? You could create the class then check their CanXXX() methods. This way you could use simple inheritance. Expanding on the this you could define an interface then have your classes implement the interface.3. An alternative is to use attributes.4. Don't override. In the base class method retrieve the values from a store (config file, DB etc) based on the type of the subclass calling it. (Or use the static method to read the attributes of the subclass.)5. Use shadows. From what I understand the main problem with it is that you might call the wrong method (the base classes instead of the sub class). But if you limit the scope of the methods to protected and the base class is MustInherit then the chances of this happening are not real likely.
RockfordLhotka:I think Bayu's early suggestion is the best overall option, and it is one I considered - and may reconsider - for the framework itself. I didn't feel confident enough in the overall concept when I was writing the book, but Magenic now has a project using this technique and it is working quite well.
Copyright (c) Marimer LLC