-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change scoping from private to protected #38
base: master
Are you sure you want to change the base?
Conversation
I don't agree with that. May the library should be refactored with interfaces and allow good ways for replace the code. |
What kind of interfaces? The problem here is that using private scoping it is not possible to extend the classes if you need to use parts of it that are private. Obviously you could solve this by modifying the classes so that they implement directly the functionality you want, but the point with extending classes is precisely to avoid that, isn't it? Let's have an example. If I want to implement what xmlseclibx calls internally a "library" (in this case, an alternative to openssl and mcrypt) and be able to construct an instance of |
I need to really go through that patch. I don't fully agree with some of the changes you suggest. i.e. All the xxxOpenSSL and xxxMcrypt should remain private. If additional/alternative crypto libraries are needed then I could see either allowing cryptParams to be private or adding some accessor methods to work with it and new methods for the new crypto libraries should be created and hooked into the appropriate encrypt and sign/verify methods. |
I really think nobody should be messing with You can then of course add the methods to work with the new library, say |
@jaimeperez I also disagree with these changes, I think fabpot makes a good argument here about why you might not want protected as the default: http://fabien.potencier.org/article/47/pragmatism-over-theory-protected-vs-private See also the Circle-ellipse problem: http://en.wikipedia.org/wiki/Circle-ellipse_problem That said It's hard to satisfy the Liskov Substitution Principle without the Single Responsibility Principle, for instance the Adding a new library (like a pure php one: http://phpseclib.sourceforge.net ? ) might be better by moving the factory type switch case statement to a separate class and making it return a strategy that takes over some of the logic from So something like: interface XMLSecurityStrategy {
public function encryptData();
// ...
}
class XMLSecurityStrategyMcrypt implements XMLSecurityStrategy {
public function encryptData() {
// ...
}
}
class XMLSecurityStrategyFactory {
public function createForType($type, $params = array()) {
$params = new XMLSecurityParams();
$params->library = 'mcrypt';
// ...
return $params;
}
}
class XMLSecurityKey {
public function __construct(XMLSecurityLibrary $library) {
$this->library = $library;
}
} So in this case you could implement your own factory that has a fallback to returning a |
Using
private
instead ofprotected
for properties and methods make it difficult or even impossible to extend the classes to implement new functionalities without modifying the base class. Private scoping should only be used in the case of internal variable and methods that really should not be used, not even by child classes.