アプリ関連ニュース

Builder Design Pattern

Builder is a creative design pattern that allows you to build complex objects step by step. The pattern allows you to produce different types and representations of an object using the same building code.

Imagine a complex object that requires laborious step-by-step initialization of many nested objects and fields. This initialization code is usually buried inside a monster constructor with many parameters. Or even worse: scattered throughout the client code.

The Builder pattern suggests that you extract the object construction code out of its own class and move it to separate objects called builders.

Lets look up the code examples I wrote as below.

PHP Code Sample

<?php

/**
 * This is the original application interface 
 * where we place the methods need to develop from its concrete sub classes
 */
interface ApplicationInterface
{
    public function setDbDriver(DbDriver $dbDriver);
 
    public function query($query);
}

/**
 * This abstract class will implements the interface as we have to reference the next hierarchy object here.
 * After that we can access the methods of their sub concrete classes in our sub classes. see below.
 */
abstract class Application implements ApplicationInterface
{
   protected $dbDriver;
 
   public function setDbDriver(DbDriver $dbDriver)
   {
       $this->dbDriver = $dbDriver;
   }
}

/**
* Concrete sub classes of the original class working with the reference object's method.
*/
class android extends Application
{
    public function query($query)
    {
        $query .= "\n\n running android app query\n";
 
        return $this->dbDriver->handleQuery($query);
    }
}
 
class ios extends Application
{
    public function query($query)
    {
        $query .= "\n\n running ios app query\n";
 
        return $this->dbDriver->handleQuery($query);
    }
}


/**
* This is the interface that need to be referenced by original class instead of inheritance.
*/
interface DbDriver
{
    public function handleQuery($query);
}

/**
* Concrete classes that will have the detail implementations of the interface.
*/
class MysqlDriver implements DbDriver
{
    public function handleQuery($query)
    {
        echo "\nUsing the mysql driver: ".$query;
    }
}
 
 
class OracleDriver implements DbDriver
{
    public function handleQuery($query)
    {
        echo "\nUsing the oracle driver: ".$query;
    }
}


//client code
// client doesn't need to know any implementation details. 
// Just build the original concrete class and inject the concrete object that will be referenced.
 
$android = new android();
$android->setDbDriver(new MysqlDriver());
echo $android->query("select * from table");
 
$android->setDbDriver(new OracleDriver());
echo $android->query("select * from table");
 

$ios = new ios();
$ios->setDbDriver(new MysqlDriver());
echo $ios->query("select * from table");

$ios->setDbDriver(new OracleDriver());
echo $ios->query("select * from table");
 

C# Code Sample

using System;
using System.Collections.Generic;

namespace HelloWorld
{
    /**
     * Two Original classes referencing the same DbDriver which is the next hierarchy object
     * After that we can access the methods of their sub concrete classes in our sub classes. query method in this case
     */
    class ApplicationInterface
    {
        protected DbDriver  _dbdriver;

        public ApplicationInterface(DbDriver  dbdriver)
        {
            this._dbdriver = dbdriver;
        }

        public virtual string setDbDriver()
        {
            return "Base DB Driver:" +
                _dbdriver.query();
        }
    }

    class RefinedAbstraction : ApplicationInterface
    {
        public RefinedAbstraction(DbDriver  dbdriver) : base(dbdriver)
        {
        }

        public override string setDbDriver()
        {
            return "Refined DB Driver:" +
                base._dbdriver.query();
        }
    }


    /**
    * This is the interface that need to be referenced by original class instead of inheritance.
    */
    public interface DbDriver 
    {
        string query();
    }

    /**
    * Concrete classes that will have the detail implementations of the interface.
    */
    class MysqlDriver : DbDriver 
    {
        public string query()
        {
            return "Using the mysql driver:\n";
        }
    }

    class OracleDriver : DbDriver 
    {
        public string query()
        {
            return "Using the oracle driver:.\n";
        }
    }

    // client doesn't need to know any implementation details. 
    // Just build the original class and inject the concrete object that will be referenced.
    class Client
    {
        public void ClientCode(ApplicationInterface applicationInterface)
        {
            Console.Write(applicationInterface.setDbDriver());
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Client client = new Client();

            ApplicationInterface applicationInterface;

            applicationInterface = new ApplicationInterface(new MysqlDriver());
            client.ClientCode(applicationInterface);

            Console.WriteLine();

            applicationInterface = new RefinedAbstraction(new OracleDriver());
            client.ClientCode(applicationInterface);
        }
    }

}

By Yuuma



[Laravel] Passportを使用したBearer token認証[3]

PHPのLaravelフレームワークのPassportを使用したBearer token認証の方法について紹介します。
本記事は前回の「[Laravel] Passportを使用したBearer token認証[2]]」の続きとなります。
今回は認証テスト用ユーザーの追加をおこない、Bearer tokenの発行と認証について説明します。

続きを読む

各社のクラウドゲームプラットフォームサービスについて

各社のクラウドゲームプラットフォームサービスについて

前回、nvidiaのGeforce Nowを記事にとりあげました。
この他に
昨年からサービスを開始しているGoogleのStadiaや
先月からサービスを開始しているMicrosoftのxCloudが
あります。(どちらも現在日本でのサービスは提供されていません)

xCloudは現行のXbox Game Pass Ultimateに加入していれば
追加料金無しでサービスを利用できるようです。
日本国内で同サービスを利用できるようになるのは
2021年上半期とアナウンスされています。
Xbox Game Pass 対象のゲームが追加料金なしで
プレイすることができるなら大きなアドバンテージですね。

また、Amazonもクラウドゲームサービスの
Lunaというサービスを招待制のEarly Accessとして
提供しているようです。

StadiaはYoutube
xCloudはFacebook Gaming
LunaはTwitch
と、ライブ動画配信サービスとの連携を行い
ライブ配信から気になったゲームを起動できるような計画を
各社行っているようです。

高速、低遅延を謳う5Gモバイルネットワーク
が普及すれば、デバイス問わずコンシューマ機や
PCと同レベルのゲーム体験が行えるかもしれませんね。
(プレイ中はHD解像度以上の動画を再生し続けるような状態
なので、通信容量をすぐに使い果たしてしまいそうですが。)

水曜担当:Tanaka



Prototype Design Pattern

Prototype is a build design pattern that allows you to copy existing objects without making your code dependent on their classes.

Declare an abstract base class that specifies a pure virtual “clone” method, and maintain a dictionary of all concrete “cloneable” derived classes. Any class that needs a “polymorphic constructor” capability: It derives from the abstract base class, registers its prototypical instance, and implements the clone () operation.

So the client, instead of writing code that invokes the “new” operator on a wired class name, calls a “clone” operation on the abstract base class, supplying an enumerated string or data type that designates the class desired derivative.

Lets see PHP & C# code samples as below.

PHP

<?php

// I made a common prototype interface for cloning purpose.
// has a single function called _clone
abstract class Person {

    protected $name;

    abstract function __clone();

    function getName() {
        return $this->name;
    }
    function setName($name) {
        $this->name = $name;
    }
}

// Here is a concrete class extending the person prototype.
// we will implement the _clone method to support object cloning.
//This may contain a lot of fields and implementations but I will keep this simple for now.
class Boy extends Person {
    function __clone() {

    }
}


//here is our first time instantiation of boy concrete class
$person = new Boy();

//next time we will clone that object by using clone.
// we will also pass the name param dynamically.
// clone1
$person1 = clone $person;
$person1->setName('Hlaing');
$person1->getName();

// clone2
$person2 = clone $boy;
$person2->setName('Tin');
$person2->getName();

print_r($person1);
print_r($person2);
 
?>

C#

using System;
using System.Collections.Generic;

namespace HelloWorld
{
    // Here is my simple object that support object cloning.
    // I already build a function called copyclone to clone this object.
    public class Person
    {
        public string Name;

        public Person CopyClone()
        {
            return (Person)this.MemberwiseClone();
        }
    }

    
    class Program
    {
        static void Main(string[] args)
        {
            // firstly we build a object using new instantiation
            Person person = new Person();

            //next time we will clone that object by theh function copyclone.
            // we will also pass the name param dynamically.
            // clone1
            Person person1 = person.CopyClone();
            person1.Name = "Hlaing";

            // clone2
            Person person2 = person.CopyClone();
            person2.Name = "Tin";


            Console.WriteLine(person1.Name);
            Console.WriteLine(person2.Name);
        }   
    }
}

By Yuuma.



Oculus Quest 2 続報

先日のFacebook Connectで発表のあった「Oculus Quest 2」ですが、そのスペックと戦略的な価格設定から発売前からとても話題になっています。
VR系の製品紹介やゲーム実況などをおこなっている何人かのYouTuberのもとには、発売前の「Oculus Quest 2」の実機が先行して届けられているようで、「Oculus Quest 2」の開封動画や製品紹介、比較動画などが、アップロードされはじめています。
今回はそれらの動画やレビューを視聴しての感想をかきたいと思います。

続きを読む

アプリ関連ニュース

お問い合わせはこちら

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

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

お問い合わせフォーム