アプリ関連ニュース

Dependency Injection in PHP

Dependency injection is the process by which one object provides the dependencies of another object. Dependency injection is a software design approach that avoids hard-coded dependencies and allows you to change dependencies at runtime and compile time.

Lets take a look along with the examples. Lets say we have a Food class that will supply dependency to Dinner Class.

<?php
class Food
{
    protected $food;
    
    public function __construct($food)
    {
    	$this->food = $food;
    }
    
    public function get()
    {
    	return $this->food;
    }
}

After that, lets create a dinner class without dependency injection first.

<?php
class Dinner
{   
    public function eat()
    {
    	$food = new Food("Chicken soup");
        return $food->get();
    }
}

$dinner = new Dinner();
echo $dinner->eat(); //output - Chicken soup

In the above style of Dinner class, we have hardcoded food class that is bad in coupling and not well dependency injected. Lets fix our dinner class using dependency injection.

<?php 

class Dinner
{  
	protected $dinner;
    
    //receiving the dependency object food.
	public function __construct(Food $food)
    {
    	$this->dinner = $food;
    }
    
    public function eat()
    {
        return $this->dinner->get();
    }
}

$food = new Food("Chicken soup");
//supplying the food object.
$dinner = new Dinner($food);
echo $dinner->eat(); //output - Chicken soup

Now, we have added a constructor to be injected the necessary food dependency object. The code is now loosely coupled and not hardcoded in dinner class anymore.

By Yuuma.



[Laravel] Eloquentとページネーション(3)

自力でページネーションの実装をおこなうには、大変工数がかかりますが、Laravelフレームワークが用意しているページネーションを使用することで工数が大幅に軽減できます。
今回はLaravelフレームワークのページネーションの実装方法を紹介したいと思います。本記事は前回の「[Laravel] Eloquentとページネーション(2)」の続きになります。

続きを読む

GoogleのAIを使って怪物を描けるキメラペインター

Chimera Painter“を紹介しているGoogle AIのブログ
今月17日に公開されていました。

続きを読む

Apple MacBook Pro 13-Inch (M1, Late 2020)

MacBook Pro 13": Apple M1 Chip and 20-Hour Battery

Apple has released new macbook models with their own chips in late 2020 & 13inch is one of my favourites. It’s suitable for multimedia editors, software developers, and other creative professionals, and its also appealing to mainstream Mac users seeking higher performance than the MacBook Air in a laptop that’s smaller and less expensive than the flagship 16-inch MacBook Pro. The latest 13-inch MacBook Pro reviewed here is as sleek as ever and more powerful than before, thanks to Apple’s new M1 processor. Someone who wants a well performance and smaller one, this 13inch MacBook Pro will probably the best suit right now.

Here is what I am thinking about pros and cons.

PROS

  • Long battery life (I like this one most)
  • Speedy performance from Apple M1 chip
  • Brilliant Retina display
  • Excellent build quality
  • Comfortable keyboard and trackpad
  • Improved webcam

CONS

  • Only two USB-C ports
  • Stingy starting standard 256GB SSD, 8GB RAM
  • Still No touch screen

By Yuuma



Unity 2019.4.14(LTS)でStandard Assetsを使用する

今回は、Unityの現行LTS(長期サポート)バージョン「Unity 2019.4.14f1」で「Standard Assets」を使用する方法を紹介いたします。

続きを読む

アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム