In my continuing quest to improve my understanding of OPP in PHP, I have developed another project. It is closer to my field and a real life project I hope to develop, than my previous post using geometric shapes.
This draft program is the simplest version. I want to increase the complexity of this example and that requires more a complex class structure. I don't know how to do that. Here is the draft program.
class Country {
private $name = 'default name';
private $land; // The endowment of land in the country.
private $labor; // The endowment of labor in the country.
private $wheat;
private $widgets;
private $allocLand; // The proportion of land in a country that is allocated to the production of wheat.
private $allocLabor; // The proportion of labor in a country that is allocated to the production of wheat.
private $techfactor; // A factor-neutal technology coefficient for the production function.
private $wheatpower; // The power coefficient on land in the production of wheat. The function has constant returns to scale.
private $widgetpower; // The power coefficient on land in the production of widgets. The function has constant returns to scale.
private $oppcost; // The opportunity cost, in terms of wheat, of producing one additional widget.
public function __construct($name, $land, $labor, $wheat, $widgets, $allocLand, $allocLabor, $techfactor, $wheatpower, $widgetpower, $oppcost) {
$this -> name = $name;
$this -> land = $land;
$this -> labor = $labor;
$this -> wheat = $wheat;
$this -> widgets = $widgets;
$this -> allocLand = $allocLand;
$this -> allocLabor = $allocLabor;
$this -> techfactor = $techfactor;
$this -> wheatpower = $wheatpower;
$this -> widgetpower = $widgetpower;
$this -> oppcost = $oppcost;
}
public function setName($Name) {
$this -> name = $Name;
}
public function getName() {
return $this -> name;
}
public function setLand($Land) {
$this -> land = $Land;
}
public function getLand() {
return $this -> land;
}
public function setLabor($Labor) {
$this -> labor = $Labor;
}
public function getLabor() {
return $this -> labor;
}
public function setWheat($Wheat) {
$this -> wheat = $Wheat;
}
public function getWheat() {
return $this -> wheat;
}
public function setWidgets($Widgets) {
$this -> widgets = $Widgets;
}
public function getWidgets() {
return $this -> widgets;
}
public function setAllocLand($AllocLand) {
$this -> allocLand = $AllocLand;
}
public function getAllocLand() {
return $this -> allocLand;
}
public function setAllocLabor($AllocLabor) {
$this -> allocLabor = $AllocLabor;
}
public function getAllocLabor() {
return $this -> allocLabor;
}
public function setTechfactor($Techfactor) {
$this -> techfactor = $Techfactor;
}
public function getTechfactor() {
return $this -> techfactor;
}
public function setWheatpower($Wheatpower) {
$this -> wheatpower = $Wheatpower;
}
public function getWheatpower() {
return $this -> wheatpower;
}
public function setWidgetpower($Widgetpower) {
$this -> widgetpower = $Widgetpower;
}
public function getWidgetpower() {
return $this -> widgetpower;
}
public function setOppcost($oppcost) {
$this -> oppcost = $oppcost;
}
public function getOppcost() {
return $this -> oppcost;
}
public function output($zz) {
$wheat = $zz -> getTechfactor() * pow(($zz -> getLand() * $zz -> getAllocLand()), $zz -> getWheatpower()) * pow(($zz -> getLabor() * $zz -> getAllocLabor()), (1 - $zz -> getWheatpower()));
$widgets = $zz -> getTechfactor() * pow(($zz -> getLand() * (1 - $zz -> getAllocLand())), $zz -> getWidgetpower()) * pow(($zz -> getLabor() * (1 - $zz -> getAllocLabor())), (1 - $zz -> getWidgetpower()));
$zz -> setWheat($wheat);
$zz -> setWidgets($widgets);
}
public function slope($zz) {
$dy = $zz -> getTechfactor() * pow(($zz -> getLand() * $zz -> getAllocLand() - 0.1), $zz -> getWheatpower()) * pow(($zz -> getLabor() * $zz -> getAllocLabor() - 0.1), (1 - $zz -> getWheatpower())) - $zz -> getWheat();
$dx = $zz -> getTechfactor() * pow(($zz -> getLand() * (1 - $zz -> getAllocLand()) + 0.1), $zz -> getWidgetpower()) * pow(($zz -> getLabor() * (1 - $zz -> getAllocLabor()) + 0.1), (1 - $zz -> getWidgetpower())) - $zz -> getWidgets();
$zz -> setOppcost($dy / $dx);
}
}
class View {
public function __construct() {}
public function printOutput($z) {
echo "The country of " . $z -> getName() . " produced " . $z -> getWheat() . " bushels of wheat, and " . $z -> getWidgets() . " widgets.<br />";
}
public function printOppcost($z) {
echo "The opportunity cost of producing a widget in " . $z -> getName() . " is " . abs($z -> getOppcost()) . " bushels of wheat.<br />";
}
}
$alphastan = new Country('Alphastan', 100, 200, 0, 0, 0.73, 0.4, 1.25, 0.73, 0.50, 0);
$alphastan -> output($alphastan);
$alphastan -> slope($alphastan);
$betastan = new Country('Betastan', 200, 500, 0, 0, 0.58, 0.30, 1.50, 0.55, 0.40, 0);
$betastan -> output($betastan);
$betastan -> slope($betastan);
$v = new View();
$v ->printOutput($alphastan);
$v ->printOutput($betastan);
$v ->printOppcost($alphastan);
$v ->printOppcost($betastan);
The areas where I plan to increase the program's complexity is in the labor endowment, the amount of wheat and widgets produced, and the slope. I would like to sum the labor endowments for all the countries instantiated and make the labor used in production different from a country's labor endowment. I am sure that I need to do more than just make the labor properties public. A method must be developed to determine how much labor immigrates into or emigrates out of a country. I am not sure if that method, and related properties, are best located in the Country class or if a Labor class needs to be created for them.
I need to sum the wheat and widgets created in each country to determine world production amounts of wheat and widgets. These amounts will determine the amount of international trade in the world of these products. Again, I am not sure if different classes for wheat and widgets is best for the properties and methods associated with the imports and exports of these products between countries. So far to me, imports/exports seem to be a country property best left in the Country class, but not world production.
The opportunity cost property, the slope, needs to be compared across countries. That seems straightforward enough by making it public. The result of the comparison is something called comparative advantage and that is a factor in how much wheat and widgets each country produces. Again, these seem appropriate in the Country class, but as they relate to world production, they may need to be accessible to another class.
Thanks in advance. If further clarification of the project is needed I will provide it.