# Making well written classes

**URL:** <https://forum.kirupa.com/t/making-well-written-classes/318631>\
**Category:** programming\
**Created:** [January 25, 2011, 8:02pm UTC](https://forum.kirupa.com/t/making-well-written-classes/318631 "2011-01-25T20:02:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spyderfx](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@spyderfx](https://forum.kirupa.com/u/spyderfx)\
**Post date:** [January 25, 2011, 8:02pm UTC](https://forum.kirupa.com/t/making-well-written-classes/318631/1 "2011-01-25T20:02:58Z")

</div>

This is my first foray into writing classes in any language. I’m trying to be a better programmer and want to make sure that the way I’m coding is considered ‘kosher’ or best practice.

Would anyone mind looking over this class I wrote and giving me any pointers as to where I could improve it?

```auto
<?php

class TableField {

private $name;
private $input;

}

class ProductField extends TableField {
    
    public $perishable;

    public function setProductName($product_name){
        $this->name = $product_name;
    }

    public function setProductPerishable($product_perishable){
        $this->perishable = $product_perishable;
    }

    public function addProduct(){
        global $con;
        global $db_name;
        mysql_select_db($db_name, $con);
        mysql_query("INSERT INTO products (name, perishable) VALUES ('$this->name', '$this->perishable')");
        echo "Product Added";
        echo $this->name;
        echo $this->perishable;
        echo $db_name;
        mysql_close($con);
    }
}

?>

```
