Skip to content

Instantly share code, notes, and snippets.

View YutoKashiwagi's full-sized avatar
🏠
Working from home

YutoKashiwagi

🏠
Working from home
View GitHub Profile
@YutoKashiwagi
YutoKashiwagi / factoryMethodPattern.ts
Created June 22, 2021 15:11
デザインパターン: ファクトリーメソッドパターン
abstract class Product {
abstract use: () => void
}
abstract class Factory {
create = (owner: string): Product => {
const product = this.createProduct(owner)
this.registerProduct(product)
@YutoKashiwagi
YutoKashiwagi / templateMethodPattern.ts
Created June 20, 2021 10:14
デザインパターン: テンプレートメソッドパターン
abstract class AbstractDisplay {
abstract open: () => void
abstract print: () => void
abstract close: () => void
display = (): void => {
this.open()
for (let index = 0; index < 4; index++) {
this.print()
@YutoKashiwagi
YutoKashiwagi / print.ts
Created June 20, 2021 10:09
デザインパターン: Adapterパターン
interface IPrint {
printWeak: () => void
printStrong: () => void
}
class Banner {
private text: string
constructor(text: string) {
this.text = text
@YutoKashiwagi
YutoKashiwagi / iterator.ts
Last active June 20, 2021 10:02
デザインパターン: Iteratorパターン
interface IAggregate<T> {
iterator: () => T
}
interface IIterator<T> {
hasNext: () => boolean;
next: () => T;
}
class Book {
authenticate
平文パスワードを渡すと、ハッシュ化されたパスワードと一致するかを確かめ、偽であればfalse,真であればオブジェクトを返す
def authenticate(request, &login_procedure)
if has_basic_credentials?(request)
login_procedure.call(*user_name_and_password(request))
end
end
create:オブジェクトの作成と保存を同時に行い、オブジェクトを返す