Advanced Help Universal Class for Comments inheritance problem - asp.net

I have a class called Comments for articles which implements a base class of BaseArticle that class has a protected object called settings.
The settings object is a web.config section just for articles and I also have one also for blogs.
My problem is that I want to make Comments usable for blog Comments, but the class Comments inherits BaseArticle, which I want it to inhereit it's own base class BaseBlog with it's own settings.
I need to make it universal how do I do that. An example would be appreciated.
class Comments : BaseArticle {}
class Comments : BaseBlog { inheritance problem}

From my experience, starting with inheritance and base classes from the early start can cause you some trouble as you already have seen. I've learned, it is better to go from a bottom up, which means-creating classes and methods that you need, and then when you've noticed similar functionality or duplicated code, you extract it to base type or interface. Anyway, for your example code I would first go and read about Liskov Substitution Principle(LSP).
More info:
LSP in OO programming?
What is the Liskov Substitution Principle?
cheers

Related

Defining and implementing interfaces in R

I'm interested in defining and inheriting from interfaces in R. By interface, I mean OOP interfaces. I know R supports class extension. This link http://adv-r.had.co.nz/OO-essentials.html gives an example of extending a reference class in R. It defines a NoOverdraftAccount reference class that extends an Account reference class.
Instead of extending the Account reference class, I'd like to be able to define an account interface, IAccount. I would like I'd like NoOverDraftAccount to implement IAccount, such that:
NoOverDraftAccount must implement all methods in IAccount.
NoOverDraftAccount cannot declare any new public methods not already declared in IAccount.
NoOverDraftAccountcan declare private methods and properties.
What's the best way to achieve this?
The closest I've come to an answer was from the question Multiple inheritance for R6 classes. But, the question wasn't focused on interfaces.
Thanks for your time.
I don't think "declarations" make much sense in an interpreted language like R. As there's no compile step there's no way to test if something actually conforms to a declared interface without running a function on the class, something like does_class_follow(class,interface), at some point.
So I think you have to start from scratch - you need to define an interface specification class and write the does_class_follow function.
My first thought was that a class would have to know what interface(s) it conformed to so that the test could introspect this, but perhaps that's wrong and you should have a file of interface definitions and pseudo-declarations that tested everything.
For example, have some file interfaces.R that looks like:
IAccount = Interface(
public = list("deposit","withdraw")
)
Implements(Account, IAccount)
Implements(Account, NoOverDraftAccount)
Then when the package is loaded those Implements functions would run and test the classes against that specification of what an Account interface is. Whether its better to test at load time or to put these sort of things in the ./test/ folder and test them at test time using test_that or another test system is a question...
As you may be aware you'll have to implement this separately for all the OO systems in R that you want to use - S3, S4, R5, ReferenceClasses, R6, proto, R.oo and all the other ones I've forgotten...

Contract class and SysOperation framework

I have a contract/UIBuilder class for a SSRS report. I want to use the same Contaract/UIBuilder class to generate data in excel.
I have came across http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/ post. Where i found that services class is used.
I have found examples where some uses services class and a few dont.
Is it really important to use services?
Also what is the advantage of using it?
How to Use a Report Data Provider Class in a Report?
The same contract can be used in several reports by specifying it with the SRSReportParameterAttribute attribute in the reports:
[
SRSReportQueryAttribute('Cust'),
SRSReportParameterAttribute(classstr(SrsRDPContractSample))
]
public class SrsRdpSampleClass extends SRSReportDataProviderBase
{
TmpCustTableSample tmpCust;
}
I'm going to skip the 1st question because you should just try and you will have your answer as to whether it works...
the second question, you have a good blog post already--but also check out:
http://daxmusings.codecrib.com/2011/08/from-runbase-to-sysoperation-business.html
and of course the ms links:
http://msdn.microsoft.com/en-us/library/gg862488.aspx
http://www.microsoft.com/en-us/download/details.aspx?id=29215
high points include:
server side operation
separating ui elements from contract and logic
batchable

How can I remove an ACL (eg. when user/object gets removed)?

In symfony 2 documentation, they talked about adding ACLs but how can I remove them? When users or objects gets removed for example?
UPDATE
I was looking at the source Symfony\Component\Security\Acl\Dbal\AclProvider, but I didn't find functions like updateAcl, so perhaps thats not the class? Where can I find outr what class Symfony uses and use the approperiate function to remove ACE?
I recently wrote up a small blog post on this with a simple ACL Manager class to help with the ACL layer.
Check it out at http://blog.codingninja.com.au/2011/12/revoke-acl-permissions-in-symfony/
The class shuld be Symfony\Component\Security\Acl\Dbal\MutableAclProvider. The delete method is public void deleteAcl(ObjectIdentityInterface $oid)
http://api.symfony.com/2.0/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.html#method_deleteAcl

Should I use a singleton class that inherits from an instantiable class or there's another better pattern?

I've got a class called ArtificialIntelligenceBase from which you can create your own artificial intelligence configuration sending some variables to the constructor or you can make a class that inherits from ArtificialIntelligenceBase and in the constructor of this new class just call the function super() with the parameters of the configurations.
I've also created some examples of artificial intelligences in classes, AIPassive, AIAgressive and AIDefensive. Obviously all of them inherits from ArtificialIntelligenceBase.
The point is that there're only few public functions in the base class. The variables in the base class are read only and the non public functions are protected in case you need to apply some modifications on them when created another pre-defined AI.
You can also create another AI just calling the base class sending some parameters in the constructor like this: new ArtificialIntelligenceBase(param1, param2, param3, param4);
I've tought about make the classes as a singleton because the classes can never change and once setted, their variables never change.
The question is: Is the singleton the best pattern to do this? Because I'm not sure.
PD: You don't need to explain any patter, just mention the name and I'll search for how it works
PPD: I'm developing in AS3. Just in case it helps
Thanks
In general, singletons are evil. I don't see any reason in your case to use a singleton, either. It sounds like you're using your own version of a factory method pattern (using a constructor somehow?) or maybe a prototype (I don't know AS3 one bit), but if you're looking for other patterns a couple of other ones are abstract factory and builder.
You don't need to use the singleton pattern to limit yourself to using only one instance per type of class, though. It doesn't help avoid redundancy.

Utility class or Common class in asp.net

Do anyone knows about the class which has the common function which we generally use while developing web application. I have no idea what you may call it, it may be the utility class or common function class. Just for reference, this class can have some common function like:
Generate Random number
Get the file path
Get the concatinated string
To check the string null or empty
Find controls
The idea is to have the collection of function which we generally use while developing asp.net application.
No idea what you are really asking, but there already are ready-made methods for the tasks you write in various library classes:
Random.Next() or RNGCryptoServiceProvider.GetBytes()
Path.GetDirectoryName()
String.Concat() or simply x + y
String.IsNullOrEmpty()
Control.FindControl()
Gotta love the intarwebs - An endless stream of people eager to criticize your style while completely failing to address the obvious "toy" question. ;)
Chris, you want to inherit all your individual page classes from a common base class, which itself inherits from Page. That will let you put all your shared functionality in a single place, without needing to duplicate it in every page.
In your example it looks like utility class - it is set of static functions.
But I think that you should group it in few different classes rather than put all methods in one class - you shouldn't mix UI functions(6) with string functions(3,4), IO functions (2) and math(1).
As Mormegil said - those functions exists in framework, but if you want to create your own implementations then I think that for part of your function the best solution is to create extension method.

Resources