Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Documents/OOP.pdf
Binary file not shown.
Binary file added Documents/Scheme class.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 60 additions & 0 deletions Pill/01-base-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php


//Create a base class with 3 properties, 3 methods, 1 constructor and 1 destructor

//create a class
class Fruit {

//properties
public $name;
public $color;
public $taste;
public $peel;

//contruct

public function __construct(string $name, string $color, string $taste){
$this->name = $name;
$this->color = $color;
$this->taste = $taste;
}
//destruct

public function __destruct()
{
$this->peel;
}

public function getFruitDetails() {
return "<h2>Fruit</h2>
Name: {$this->name}<br>
Color: {$this->color}<br>
Type: {$this->taste}<br>";
}

//methods

public function Feed() {

echo 'I am feeding';
}

public function Hydrate() {

echo 'I am hydrating';
}

public function Regular() {

echo 'I regulate intestinal transit';
}


}





?>
44 changes: 44 additions & 0 deletions Pill/02-inherit-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

require_once ("01-base-class.php");

//1 static property 1 method This class must override: 1 property 1 method


class Kiwi extends Fruit
{

public $origin;

public function __construct(string $name, string $color, string $taste, string $origin){


parent::__construct($name, $color, $taste);

$this->origin = $origin;

}

public function getOrigin()
{
return $this->origin;
}

public function getVitamin() {

echo 'I have vitamin C';
}

public function getFruitDetails() {
return "<h2>Fruit</h2>
Name: {$this->name}<br>
Color: {$this->color}<br>
Type: {$this->taste}<br>
Origin: {$this->origin}";
}
}




?>
26 changes: 26 additions & 0 deletions Pill/03-abstract-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<?php

abstract class Citric {

abstract public function getUses();
abstract public function values($uses);


public function Uses(){
echo $this->getUses();
}

}

class Lemon extends Citric {
public function getUses(){
return " ";
}

public function values($uses){
return "Lemon is useful for " . $uses;
}
}

?>
35 changes: 35 additions & 0 deletions Pill/04-interfaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

interface healthyFood {
public function Feed();
public function Hydrate();
public function Regular();
public function getVitamin();
}

class Fruit implements healthyFood {
public function Feed() {

echo 'I am feeding';
}

public function Hydrate() {

echo 'I am hydrating';
}

public function Regular() {

echo 'I regulate intestinal transit';
}
}

class Kiwi implements healthyFood {
public function getVitamin() {

echo 'I have vitamin C';
}

}

?>
29 changes: 29 additions & 0 deletions Pill/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require_once ("02-inherit-class.php");
require_once ("03-abstract-class.php");


$myFruit = new Fruit('mandarin', 'orange', 'acid');
echo $myFruit->getFruitDetails();
echo "<br>";
echo $myFruit->Feed();
echo "<br>";
echo $myFruit->Hydrate();
echo "<br>";
echo $myFruit->Regular();
echo "<br>";
$Kiwi = new Kiwi ('kiwi', 'green', 'acid', 'china');
echo $Kiwi->getFruitDetails();
echo "<br><br>";
echo $Kiwi->getVitamin();
echo "<br><br><br>";

$Lemons = new Lemon;

$Lemons->Uses();
echo $Lemons->values("flu");



?>
86 changes: 12 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

# Assembler School: OOP Basics with PHP <!-- omit in toc -->

In this project you will learn the basics of OOP using mobile devices as a reference. In the _"Project files"_ section you will find a description of the content to be displayed in each file.
In this project you will learn the basics of OOP using fruits as a reference. In the _"Project files"_ section you will find a description of the content to be displayed in each file.

## Table of contents

- [Table of contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Dependencies](#dependencies)
- [Tools](#tools)
- [OOP Introduction](#oop-introduction)
- [Project files](#project-files)

## Getting Started

### The repo <!-- omit in toc -->

Expand All @@ -23,10 +21,11 @@ First, you will need to clone the repo:
$ git clone https://github.com/assembler-school/oop-basics.git
```

### Presentation material <!-- omit in toc -->

- [Slides](https://docs.google.com/presentation/d/1cZxutGPDqUGsLWLVen_ATjd7dEkeoPS_v_fy1y0C5Co/edit?usp=sharing)
### Wireframes <!-- omit in toc -->

- Documents folder:
- OOP: Document with basics concepts
- Scheme class: Document with a wireframe of the pill.
## Dependencies

Before we can get started you will need to make sure that all the necessary dependencies are installed in your system.
Expand All @@ -45,92 +44,31 @@ $ php -version

In the event that you prefer to use a tool that installs everything you need to configure and run a PHP server, we recommend using [XAMPP](https://www.apachefriends.org/es/download.html)

### XAMPP <!-- omit in toc -->

XAMPP is a completely free and easy to install Apache distribution that contains MariaDB, PHP, and Perl. The XAMPP installation package has been designed to be incredibly easy to install and use.

<img src='./assets/img/xampp-homepage.png' width='600' alt='xampp homepage'>

You have to go to the [download page](https://www.apachefriends.org/es/download.html) and it will automatically recommend installing the latest version available.

<img src='./assets/img/xampp-download.png' width='600' alt='xampp download'>

Once downloaded and installed, in the case that the Windows operating system you will see the following screen, in which you will only have to start the Apache service.

<img src='./assets/img/xampp-app.png' width='600' alt='xampp app'>

## OOP Introduction

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

## Project files

### [01 - Classes](./01-classes.php) <!-- omit in toc -->

The OOP paradigm encapsulates concepts of the real world in what is called as Classes which create Objects. In this file you will learn how to create a class and instanciate it.

### [02 - Properties](02-properties.php) <!-- omit in toc -->

Class member variables are called properties. In this file, you will learn how to add properties to a class and get them when the class is instantiated.

### [03 - Methods](03-methods.php) <!-- omit in toc -->

Properties define the characteristics of an object and the methods (functions in a class are called methods) which define the behavior of the Class. In this file you will learn how to create methods inside a class.

### [04 - Getters](04-getters.php) <!-- omit in toc -->

The get method returns the attribute value, usually there is a get method for each attribute of the class. In this file you will learn how to create **getter** methods.

### [05 - Setters](05-setters.php) <!-- omit in toc -->
### [01 - Base Class](./Pill/01-base-class.php01-base-class.php) <!-- omit in toc -->

The set method sets the attribute value, usually there is a get method for each attribute of the class. In this file you will learn how to create **setter** methods.
The OOP paradigm encapsulates concepts of the real world in what is called as Classes which create Objects. In this file you will learn how to create a class and implement methods.

### [06 - Constructors](06-constructors.php) <!-- omit in toc -->

A constructor allows you to initialize an object's properties upon creation of the object. In this file you will learn how to create the constructor method.

### [07 - Inheritance problem](07-inheritance-problem.php) <!-- omit in toc -->

There are several disadvantages of not applying inheritance in our code. In this file you will lean what's the problem if you don't apply any inheritance in your code.

### [08 - Inheritance soluction](08-inheritance-solution.php) <!-- omit in toc -->
### [02 - Inherit class](./Pill/02-inherit-class.php) <!-- omit in toc -->

The child class will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own properties and methods. In this file you will learn how to apply the inheritance in your code.

### [09 - Public, private & protected](09-public-private-protected.php) <!-- omit in toc -->

Properties and methods can have access modifiers which control where they can be accessed. In this file you will learn le three access modifiers.

### [10 - Static](10-static.php) <!-- omit in toc -->

Static properties and methods can be called directly - without creating an instance of the class first. In this file you will learn how to use static properties and methods.

### [11 - Const](11-const.php) <!-- omit in toc -->

Constants cannot be changed once it is declared. Class constants can be useful if you need to define some constant data within a class. In this file you will learn how to create constants within a class.

### [12 - Abstract classes](12-abstract-classes.php) <!-- omit in toc -->
### [03 - Abstract class](./Pill/03-abstract-class.php) <!-- omit in toc -->

Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. In this file you will learn how to create and use abstract classes.

### [13 - Interfaces](13-interfaces.php) <!-- omit in toc -->
### [04 - Interfaces](./Pill/04-interface.php) <!-- omit in toc -->

Interfaces allow you to specify what methods a class should implement.
Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism". In this file you will learn how to create and extend interfaces.

### [14 - Overriding](14-overriding.php) <!-- omit in toc -->

In function overriding, both parent and child classes should have same function name with and number of arguments. In this file you will learn how to implement overriding.

### [15 - Overloading](15-overloading.php) <!-- omit in toc -->

Function overloading contains same function name and that function preforms different task according to number of arguments. In this file you will learn how to implement overloading.

### [16 - Namespaces](16-namespaces.php) <!-- omit in toc -->

Namespaces are qualifiers that solve two different problems:
### [Index](./Pill/index.php) <!-- omit in toc -->

1. They allow for better organization by grouping classes that work together to perform a task
2. They allow the same name to be used for more than one class
In this document you will find all the instances of the pill.

In this file you will learn how to create and use namespaces.
Binary file removed assets/img/xampp-app.png
Binary file not shown.
Binary file removed assets/img/xampp-download.png
Binary file not shown.
Binary file removed assets/img/xampp-homepage.png
Binary file not shown.