Question: I have a doubt about the design of a system to manage items of a store using OOP.
I created the abstract class Product that will have the attributes $name and $price. Later I created the class Smartphone that extends Product. Smartphone has the attributes $brand and $os. Later I created the class Computer that extends Product and has attributes $cpuFrequency and $ram. Now, if I want to create an object corresponding to the Nexus 5, for example, what i have to do?
Consider, for example, that this object will have

```
$name = "Nexus 5"
$price = "250"
$brand = "LG"
$os="Android"
$cpuFrequency "2.0"
$ram = "2".

```

Here an example of classes.

```
abstract class Product {
    private $name;
    private $price; 
    //more methods
}

class Smartphone extends Product{
    private $brand;
    private $os;    
}

class Computer extends Product {
    private $cpuFrequency;
    private $ram;   
}

```

Also considered that there may be Computer without $os and Smartphone without $ram. just one example: D

P.S. I know that smartphone is a computer. I did a bad example. Please think at Telephone and Computer. Telephone has $number and $operator. Now i want to create a Smartphone that is at the same time Telephone and Computer.

Thanks for all and sorry again for my english

Answer: 
Normally, you should write constructors to your classes in some way that "child" class initialize the super class, to keep everything consistent.

```
abstract class Product {
    private $name;
    private $price; 
    //more methods

    public __construct($name, $price){
        $this->name = $name;
        $this->price =$price;
    }
}

class Smartphone extends Product{
    private $brand;
    private $os;
    // default value to $os: like that, we can create a Smartphone whitout an os
    public __construct($name, $price, $brand, $os = null){
        parent::__construct($name, $price);
        $this->brand = $brand;
        $this->os =$os;
    }
}

class Computer extends Product {
    private $cpuFrequency;
    private $ram;
    // default value to $ram: with this, we can create a Computer whiout ram
    public __construct($name, $price, $frequency, $ram = null){
        parent::__construct($name, $price);
        $this->frequency = $frequency;
        $this->ram =$ram;
    }

}

```

Then, to create a *Computer*, you can do, for 

```
$computer = new Computer('notBuiltToWindows', 560 , 2.0, 4);

```

or, to create the Nexus in your example:

```
$nexus = new Smartphone($name, $price, $frequency, $ram);

```

and, to create a smartphone whitout a ram

```
$nexus = new Smartphone($name, $price, $frequency);

```
As others have said, making too many classes can get confusing.

The idea is to create a class that can cover many different scenarios, without too much work.

For example, you could have a class `Pet`. A dog is a pet, and so can a snake... This doesnt mean you should make a `FourLegged` or `Nolegs` class.

Much like your products, you may have a `product` class that holds things common to all products. You may even want to have a sub class called `electronics` that can cover everything from phones to computers.

You may have a `productType` attribute that says what kind of electronic it is (e.g phone), but ultimately, there won't be too much variation between individual electronics: TV's, smartphones and computers both have screen specs, a smartphone and computer have ram, cpu's etc.