Partial Classes
If we are using same class for different purposes we can extend it, and add
new properties and methods. But we will also have to use new class name,
when we create objects. C# provides a better concept "Partial Classes". Why
not to also implement it in PHP?
Example:
Partial Class abc {
public function sayhi() {
echo "Hi";
}
}
Partial Class abc {
public function sayhello() {
echo "Hello";
}
}
Q: What will happen if both classes contain same method names?
A: We will show error method already exists.
Q: Will it break any existing code?
A: No, there will be no impact on any existing coding because we are not
changing anything.
Partial Classes
If we are using same class for different purposes we can extend it,
and add new properties and methods. But we will also have to use new
class name, when we create objects. C# provides a better concept
"Partial Classes". Why not to also implement it in PHP?Example:
Partial Class abc {
public function sayhi() {
echo "Hi";
}}
Partial Class abc {
public function sayhello() {
echo "Hello";
}}
My understanding is that C# mostly uses this for GUI stuff where
forms/widgets are designed in a visual editor and code is written in
text. By using partial classes those can be in different files, thus
developers don't touch generated files.
Except for that a need for splitting this up indicates a design issue
to me. Like a class doing too many things.
PHP has traits which you eventually can use to emulate such a system in
a more explicit way.
http://php.net/traits
Q: What will happen if both classes contain same method names?
A: We will show error method already exists.Q: Will it break any existing code?
A: No, there will be no impact on any existing coding because we are
not changing anything.
It would break usage of "partial" which is not a keywor, yet.
johannes
06.07.2017 15:34 "Johannes Schlüter" johannes@schlueters.de napisał(a):
Partial Classes
If we are using same class for different purposes we can extend it,
and add new properties and methods. But we will also have to use new
class name, when we create objects. C# provides a better concept
"Partial Classes". Why not to also implement it in PHP?
Because class in few files won't autoload and more files cause you don't
have class in one place and switching through files may increase
frustration.
Also this would lead to ambiguity if you load few partial classes which
uses methods from not-loaded one how can you know where to find it?
Example:
Partial Class abc {
public function sayhi() {
echo "Hi";
}}
Partial Class abc {
public function sayhello() {
echo "Hello";
}}
My understanding is that C# mostly uses this for GUI stuff where
forms/widgets are designed in a visual editor and code is written in
text. By using partial classes those can be in different files, thus
developers don't touch generated files.Except for that a need for splitting this up indicates a design issue
to me. Like a class doing too many things.PHP has traits which you eventually can use to emulate such a system in
a more explicit way.
http://php.net/traitsQ: What will happen if both classes contain same method names?
A: We will show error method already exists.Q: Will it break any existing code?
A: No, there will be no impact on any existing coding because we are
not changing anything.It would break usage of "partial" which is not a keywor, yet.
johannes