I don't want to define a method in a base class as abstract but I need that method to exist. Is it ok to do...

What does chmod -u do?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

How can I block email signup overlays or javascript popups in Safari?

Evaluating expression with Integer part and Fraction part of a nested radical

Why is it that I can sometimes guess the next note?

Is it better practice to read straight from sheet music rather than memorize it?

How could a planet have erratic days?

How does a computer interpret real numbers?

Is aluminum electrical wire used on aircraft?

Is there a RAID 0 Equivalent for RAM?

Did arcade monitors have same pixel aspect ratio as TV sets?

Why Shazam when there is already Superman?

What is this called? Old film camera viewer?

Count the occurrence of each unique word in the file

How should I respond when I lied about my education and the company finds out through background check?

What will be next at the bottom row and why?

What if a revenant (monster) gains fire resistance?

Explaining alternative travel routes when going to the USA

Why electric field inside a cavity of a non conducting not zero

Why a symmetric relation is defined: ∀x∀y( xRy⟹yRx) and not ∀x∀y (xRy⟺yRx)?

Basic combinatorial probability problem

The screen of my macbook suddenly broken down how can I do to recover

What is going wrong in this circuit which supposedly should step down AC to arduino friendly voltage?

Redundant comparison & "if" before assignment



I don't want to define a method in a base class as abstract but I need that method to exist. Is it ok to do this? [closed]


Object Paradigm for PHP, Practice in DesignPHP my way of threating static classesWhat is the best way to get the child class name for use in a parent class“fake” covariance in PHP type-hintingBasic PHP Factory PatternSimple PHP inheritance using an abstract classFactory dependency injectorMultiple-configurations class for practice and later useClass to create dynamic php + mysql queries (safely)MVC structured REST API in PHP













0












$begingroup$


I have a method (send) that needs to access another method (beforeSend). BeforeSend might be defined in child classes to make some checks.
With the approach I have bellow I don't like the fact that beforeSend() is a simple method that returns true. I want to know if this is OK.



Originally I had beforeSend as an abstract method so all extending classes needed to define that method (but again, there would be some classes where the method would return true I didn't like that). The problem with this approach is that I know that in the future I'm going to need to subclass one of those child classes and I won't have a way to force the children of that class to implement beforeSend.



abstract class Base
{

public function beforeSend()
{
echo 'beforeSend in Abstract' . "n";
return true;
}


public function send()
{
if ($this->beforeSend()) {
echo 'SENDING' . "n";
}
}

}

class Foo extends Base
{

public function beforeSend()
{
echo 'beforeSend in Foo' . "n";
return true;
}

}

class Bar extends Base
{
//no beforeSend defined because i dont need to check anything
}


$a = new Foo();
$a->send();

$b = new Bar();
$b->send();









share|improve this question









$endgroup$



closed as off-topic by Mast, Vogel612 Mar 14 at 18:41


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1




    $begingroup$
    I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
    $endgroup$
    – πάντα ῥεῖ
    Mar 14 at 18:03












  • $begingroup$
    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
    $endgroup$
    – Zeta
    Mar 14 at 18:06






  • 1




    $begingroup$
    This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    $endgroup$
    – Mast
    Mar 14 at 18:40










  • $begingroup$
    As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:44












  • $begingroup$
    Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:51
















0












$begingroup$


I have a method (send) that needs to access another method (beforeSend). BeforeSend might be defined in child classes to make some checks.
With the approach I have bellow I don't like the fact that beforeSend() is a simple method that returns true. I want to know if this is OK.



Originally I had beforeSend as an abstract method so all extending classes needed to define that method (but again, there would be some classes where the method would return true I didn't like that). The problem with this approach is that I know that in the future I'm going to need to subclass one of those child classes and I won't have a way to force the children of that class to implement beforeSend.



abstract class Base
{

public function beforeSend()
{
echo 'beforeSend in Abstract' . "n";
return true;
}


public function send()
{
if ($this->beforeSend()) {
echo 'SENDING' . "n";
}
}

}

class Foo extends Base
{

public function beforeSend()
{
echo 'beforeSend in Foo' . "n";
return true;
}

}

class Bar extends Base
{
//no beforeSend defined because i dont need to check anything
}


$a = new Foo();
$a->send();

$b = new Bar();
$b->send();









share|improve this question









$endgroup$



closed as off-topic by Mast, Vogel612 Mar 14 at 18:41


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1




    $begingroup$
    I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
    $endgroup$
    – πάντα ῥεῖ
    Mar 14 at 18:03












  • $begingroup$
    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
    $endgroup$
    – Zeta
    Mar 14 at 18:06






  • 1




    $begingroup$
    This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    $endgroup$
    – Mast
    Mar 14 at 18:40










  • $begingroup$
    As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:44












  • $begingroup$
    Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:51














0












0








0





$begingroup$


I have a method (send) that needs to access another method (beforeSend). BeforeSend might be defined in child classes to make some checks.
With the approach I have bellow I don't like the fact that beforeSend() is a simple method that returns true. I want to know if this is OK.



Originally I had beforeSend as an abstract method so all extending classes needed to define that method (but again, there would be some classes where the method would return true I didn't like that). The problem with this approach is that I know that in the future I'm going to need to subclass one of those child classes and I won't have a way to force the children of that class to implement beforeSend.



abstract class Base
{

public function beforeSend()
{
echo 'beforeSend in Abstract' . "n";
return true;
}


public function send()
{
if ($this->beforeSend()) {
echo 'SENDING' . "n";
}
}

}

class Foo extends Base
{

public function beforeSend()
{
echo 'beforeSend in Foo' . "n";
return true;
}

}

class Bar extends Base
{
//no beforeSend defined because i dont need to check anything
}


$a = new Foo();
$a->send();

$b = new Bar();
$b->send();









share|improve this question









$endgroup$




I have a method (send) that needs to access another method (beforeSend). BeforeSend might be defined in child classes to make some checks.
With the approach I have bellow I don't like the fact that beforeSend() is a simple method that returns true. I want to know if this is OK.



Originally I had beforeSend as an abstract method so all extending classes needed to define that method (but again, there would be some classes where the method would return true I didn't like that). The problem with this approach is that I know that in the future I'm going to need to subclass one of those child classes and I won't have a way to force the children of that class to implement beforeSend.



abstract class Base
{

public function beforeSend()
{
echo 'beforeSend in Abstract' . "n";
return true;
}


public function send()
{
if ($this->beforeSend()) {
echo 'SENDING' . "n";
}
}

}

class Foo extends Base
{

public function beforeSend()
{
echo 'beforeSend in Foo' . "n";
return true;
}

}

class Bar extends Base
{
//no beforeSend defined because i dont need to check anything
}


$a = new Foo();
$a->send();

$b = new Bar();
$b->send();






php






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 14 at 17:49









Guillemo MansillaGuillemo Mansilla

1011




1011




closed as off-topic by Mast, Vogel612 Mar 14 at 18:41


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Mast, Vogel612 Mar 14 at 18:41


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    $begingroup$
    I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
    $endgroup$
    – πάντα ῥεῖ
    Mar 14 at 18:03












  • $begingroup$
    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
    $endgroup$
    – Zeta
    Mar 14 at 18:06






  • 1




    $begingroup$
    This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    $endgroup$
    – Mast
    Mar 14 at 18:40










  • $begingroup$
    As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:44












  • $begingroup$
    Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:51














  • 1




    $begingroup$
    I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
    $endgroup$
    – πάντα ῥεῖ
    Mar 14 at 18:03












  • $begingroup$
    Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
    $endgroup$
    – Zeta
    Mar 14 at 18:06






  • 1




    $begingroup$
    This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    $endgroup$
    – Mast
    Mar 14 at 18:40










  • $begingroup$
    As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:44












  • $begingroup$
    Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
    $endgroup$
    – ArtisticPhoenix
    Mar 15 at 18:51








1




1




$begingroup$
I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
$endgroup$
– πάντα ῥεῖ
Mar 14 at 18:03






$begingroup$
I'm not a PHP expert, but from an experienced OOP point of view it's completely fine to let abstract base classes having default implementations for certailn operations (callbacks). Though the abstract class shouldn't be the primary contract, speaking by means of c++ terminology a struct with all pure virtual function declarations.
$endgroup$
– πάντα ῥεῖ
Mar 14 at 18:03














$begingroup$
Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Zeta
Mar 14 at 18:06




$begingroup$
Welcome to Code Review. The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Zeta
Mar 14 at 18:06




1




1




$begingroup$
This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
$endgroup$
– Mast
Mar 14 at 18:40




$begingroup$
This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
$endgroup$
– Mast
Mar 14 at 18:40












$begingroup$
As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
$endgroup$
– ArtisticPhoenix
Mar 15 at 18:44






$begingroup$
As a PHP guy, I would create these "things" interface SendableInterface, interface UnsendableInterface, abstract class AbstractBase, abstract class AbstractSendable extends Base implements SendableInterface, abstract class AbstractUnSendable extends AbstractBase implements unsendable Then when you do Bar class Bar extends AbstractUnSendable and when you do Foo class Bar extends AbstractSendable - the interfaces are nice if you need another sub-sub branch.
$endgroup$
– ArtisticPhoenix
Mar 15 at 18:44














$begingroup$
Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
$endgroup$
– ArtisticPhoenix
Mar 15 at 18:51




$begingroup$
Also don't forget about traits which can be used to bridge branches of the tree horizontal inheritance. You should be cautious with Traits as they can lead to spaghettification of your code, but they can also be nice for common functionality when used correctly. I like to prefix Abstract and suffix Interface to the names its also in the PSR-1 coding standard. php-fig.org/psr/psr-1 as is naming them Studly case (like proper nouns, or with Capitals)
$endgroup$
– ArtisticPhoenix
Mar 15 at 18:51










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...