Scenario
Base Class A and its Sub Classes are B, C, D, E, F
Every class have a method B_Menu(), C_Menu(), D_Menu(), E_Menu(), F_Menu() respectively. And following Search_Form ($FileName,$Heading,$SubHeading) method with different x_Menu() method where x=B, C, D, E, F for every Sub Class mentioned below: - <?php function Search_Form($FileName,$Heading,$SubHeading){ ?>
-
<FORM method="POST" action="<?php echo $filename;?>">
-
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="AutoNumber1" height="344"><?php $this->Page_Heading("$Heading"); ?>
-
<tr> <td width="100%" height="51" colspan="2"><BR>
- <?php if($Heading=="REPORT")$this->B_Menu(); ?>
-
<p align="center"><b><font size="4"> <u>SEARCH FOR<?php echo $SubHeading; ?></u></font></b></td></tr><tr><td width="50%" height="51"><strong>User's ID :</strong></td><td width="50%" height="51">
-
<p align="center"><input type="text" name="PatID" size="10"></td></tr><tr>
-
<td width="100%" height="19" colspan="2">
-
------------------------------------------------------OR-------------------------------------------------</td>
-
</tr><tr><td width="50%" height="51"><strong>First Name :</strong></td>
-
<td width="50%" height="51"><p align="center"><select size="1" name="FName">
-
<option selected>Select First Name...</option></select></td></tr><tr>
-
<td width="50%" height="51"><strong>Last Name : </strong></td>
-
<td width="50%" height="51"><p align="center"><select size="1" name="LName">
-
<option selected>Select Last Name...</option></select></td></tr></table>
-
<p align="center"><?php $this->Submit_Reset(" Search "," Reset "); ?> </p></FORM><?php }
………..
Calling Search_Form ($FileName,$Heading,$SubHeading) method as follows: - ObjA-> Search_Form (‘x.php’,’REPORT’,’Update’);
-
ObjB-> Search_Form (‘y.php’,’REPORT’,’Delete’);
:
:
: Question?
If I move Search_Form ($FileName,$Heading,$SubHeading) method to Base Class A
What changes are required? and how can I call it in any Sub Class?
16 8296
pleas edit you code and set the [code] tags properly
any way from the description i got the following idea
you have a base class A -
<?php
-
class ClassA
-
{
-
public function Search_Form ($FileName,$Heading,$SubHeading)
-
{
-
//do something here
-
echo $FileName . "<br>";
-
}
-
}
-
-
class ClassB extends ClassA
-
{
-
public function B_Menu()
-
{
-
-
}
-
}
-
-
class ClassC extends ClassA
-
{
-
public function C_Menu()
-
{
-
-
}
-
}
-
-
class ClassD extends ClassA
-
{
-
public function D_Menu()
-
{
-
-
}
-
-
public function search()
-
{
-
$this->Search_Form('d1', 'd2', 'd3');
-
}
-
}
-
-
$b = new ClassB();
-
$b->Search_Form('b1', 'b2', 'b3');
-
-
$c = new ClassC();
-
$c->Search_Form('c1', 'c2', 'c3');
-
-
$d = new ClassD();
-
$d->search();
-
?>
-
this works because ClassB & ClassC are extending ClassA
so they can access the parent Class methods.
from a sub class $this can use to access parent class methods
Regards
hi
May be I can't convey my issue Now another try
a search() define in every sub class and in the search() another function of sub class menu() is call like this: - search()
-
{
-
//screen design in html
-
$this->menu();
-
//this is the different line in every subclass because menu() is
-
//different in every sub class
-
//screen design in html
-
}
Because search() is repeat in all sub classes I want to move it on base class
so what are the changes required to move search() into base class and how to call search() in every subclass with different menu();
there is no objection of moving search() in the base class (especially since it’s the same for every subclass)
you call it the same way: $this->search(). as long as there is no search() method in the current class, PHP looks it up in each ancestor class, until it finds the method.
Yes you are right but how to use the menu() in search() because every subclass have menu() with different functionally.
e.g.
sub class A have 2 menu() which are menu1() & menu2()
sub class B have 3 menu() which are menu1() , menu2() & menu3()
sub class C have 1 menu() which is menu1()
could you please post the codes of the classes so i can analyse them properly
i really didn't get your question this time
Regards
I can’t see menu() used in search().
-
class main
-
{
-
//other base class functions
-
}
-
class A extend main
-
{
-
menu1(){//Use in search()
-
//screen design in html
-
}
-
menu2(){
-
//screen design in html
-
}
-
search() {
-
//screen design in html
-
$this->menu1();
-
//this is the different line in every subclass because menu() is
-
//different in every sub class
-
//screen design in html
-
}
-
}
-
class B extend main
-
{
-
menu1(){
-
//screen design in html
-
}
-
menu2(){//Use in search()
-
//screen design in html
-
}
-
menu3(){
-
//screen design in html
-
}
-
search() {
-
//screen design in html
-
$this->menu2();
-
//this is the different line in every subclass because menu() is
-
//different in every sub class
-
//screen design in html
-
}
-
}
-
-
class A extend main
-
{
-
menu1(){//Use in search()
-
//screen design in html
-
}
-
search() {
-
//screen design in html
-
$this->menu1();
-
//this is the different line in every subclass because menu() is
-
//different in every sub class
-
//screen design in html
-
}
-
}
-
you could work around that with an abstract class. - abstract class Main
-
{
-
abstract public function menu();
-
public function search()
-
{
-
// some code with $this->menu()
-
}
-
}
-
-
class A extends Main
-
{
-
public function menu()
-
{
-
// code for menu in A
-
}
-
}
-
-
$x = new A;
-
$x->search();
As I mention in sample code
In sub calss A menu1() call in search()
In sub calss B menu2() call in search()
In sub calss C menu1() call in search()
It means I define 2 or 3 abstract functions in base class like this:
abstract public function menu1();
abstract public function menu2();
.....
Am I right??
if you make it a common name in each subclass, it’s way easier to handle than with different names. besides, since you define search() in Main, there is no implementation of search() in either subclass (you always use the same code).
of course you could do it this way, but that means you have to define menu1() and menu2() in each subclass (–> not worth it)
Yes you are right but if functions are different like this: - class main
-
{
-
//other base class functions
-
}
-
class A extend main
-
{
-
Customer(){//Use in Design()
-
//screen design in html
-
}
-
Design() {
-
//screen design in html
-
$this->Customer(); //Only this is the different line in every subclass
-
//screen design in html
-
}
-
}
-
class B extend main
-
{
-
Saller(){//Use in Design()
-
//screen design in html
-
Design() {
-
//screen design in html
-
$this->Saller();//Only this is the different line in every subclass
-
//screen design in html
-
}
-
}
-
-
class C extend main
-
{
-
Resaller(){//Use in Design()
-
//screen design in html
-
Design() {
-
//screen design in html
-
$this->Resaller();//Only this is the different line in every subclass
-
//screen design in html
-
}
-
}
-
Problem
Because every subclass have same function Design() but different function call of its class.
And Design() function repeat in every subclass so I need to move this funtion to Base class to avoid repeatation but If I move this funtion how can I call different funtions of every subclass in it??
i.e.
In class A I need to call Customer(); in it
In class B I need to call Saller(); in it
In class C I need to call Resaller(); in it
then you can’t move it to the base class.
if Customer(), Seller() & Reseller() are doing different things (as the name suggests) there is (for me) no reason why Design() should be the same for each. there might be a totally different solution that suits your needs, but that depends on the whole picture.
if it’s just the call to these methods (and these methods don’t interact with the rest of the code) why don’t you define it this way: - class Main
-
{
-
protected function searchMe()
-
{
-
// common code
-
}
-
}
-
-
class A extends Main
-
{
-
public function search()
-
{
-
$this->Customer();
-
$this->searchMe();
-
}
-
}
Atli 5,058
Expert 4TB
I would probably do something like this - <?php
-
-
abstract class Main
-
{
-
abstract protected function drawCustom();
-
-
function Draw()
-
{
-
# Print HTML...
-
-
$this->drawCustom();
-
-
# Print more HTML
-
}
-
}
-
-
class MainCustomer extends Main
-
{
-
protected function drawCustom()
-
{
-
# Draw stuff for Customer
-
}
-
}
-
class MainSeller extends Main
-
{
-
protected function drawCustom()
-
{
-
# Draw stuff for Seller
-
}
-
}
-
class MainReseller extends Main
-
{
-
protected function drawCustom()
-
{
-
# Draw stuff for Reseller
-
}
-
}
-
-
?>
You could use the drawCustom() overwrite in each child class to do whatever you wanted. Leave it empty, even, if you don't need it.
Thank I try both options.
I’d try Atli’s option, since that got 2 votes.
Thank you both of the Moderators to solve my problem you are the only two person who resolve my problem I send my problem to ten different groups and forums but no one solve it except you.
Thanks Again.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fabian Müller |
last post by:
Hi all,
my question is as follows:
If have a class X and a class Y derived from X.
Constructor of X is X(param1, param2) .
Constructor of...
|
by: Randell D. |
last post by:
Folks,
I'm sure this can be done legally, and not thru tricks of the trade - I
hope someone can help.
I'm writing a 'tool' (a function) which...
|
by: Daniel Kay |
last post by:
Hello!
I have written two template classes which implement the observerpattern
in C++. I hope I manage to desribe the problem I have.
...
|
by: John A. Prejean |
last post by:
This one has me stumped. I have a base form I am trying to wrap up, but I
have one problem. In two functions I am opening a "record detail" form. ...
|
by: alexandre.braganti |
last post by:
Hello,
First sorry for my poor English, I am French ;-)
I've got a comprehension problem of what happend in one of the project
i'm working on.
...
|
by: Taran |
last post by:
Hi All,
I tried something with the C++ I know and some things just seem
strange.
consider:
#include <iostream>
using namespace std;
|
by: roland.bali |
last post by:
Hi,
Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load....
|
by: Javier |
last post by:
Hello, is this possible?
I have a pure virtual function in the base class (to force the
programmers of the derived classes to have this function...
|
by: dolphin |
last post by:
Hi All!
I have a question that how to call a function just using a string.
For example
There is a .cpp file named a.cpp.There are some...
|
by: ManicQin |
last post by:
Hi lets say I have the next situation
class base
{
pubic: ;)
base() {}
virtual ~base(){}...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
| |