Design Pattern Question

I’m relatively new to the world of OOP, and having read through some design patterns, I’m struggling with that ‘aha’ moment.

I have the following objects
Event (Single event, with start time and end time, and it’s availability)
EventCollection (Contains multiple instances of the Event, either cloned and set, or instantiated with ‘new’, and a date attribute)
Booking (With a collection of EventCollections)

This in turn, gives the ability to pick multiple event ‘slots’ per day.

The object, EventCollection will either contain static pre-computed time ‘slots’, for ‘picking’, or a set of Events for which have been booked.

Now my first stab at this, at least up to the point of EventCollection has been along these lines

class Event {
    protected startTime
    protected endTime
    protected status //available, booked, unavailable

    public function __construct(startTime, endTime, status = 'available')
    {
        this->startTime = startTime
        this->endTime = endTime
        this->status = status
    }

    public function changeStatus(status)
    {
        this->status = status
    }

    public function getStatus()
    {
        return this->status
    }
}

class EventCollection {
    protected date
    protected events

    public function __construct(date)
    {
        this->date = date
    }

    public function buildAvailableEvents()
    {
        // Loop through construction of events calculated by pre defined offsets
        this->events[] = new Event(startTime, endTime, 'available')
    }

    public function populateFromDb(SomeInterface db)
    {
        // Loop through construction of events determined by the interface of a database source
        this->events[] = new Event(startTime, endTime, status)
    }

    public function getAvailableEvents()
    {
        return this->getEvents('available')
    }

    public function getBookedEvents()
    {
        return this->getEvents('booked')
    }

    public function getUnavailableEvents()
    {
        return this->getEvents('unavailable')
    }

    protected function getBlocks(status)
    {
        selectedEvents = []
        foreach (this->events as event) {
            if(event->getStatus() == status)
            {
                selectedEvents[] = event
            }
        }

        return selectedEvents
    }
}

class Booking {
    protected name
    protected email
    protected moreCustomerDetails

    protected EventCollection

    public function __construct(name, email ...)
    {
        this->name = name
        this->email = email
    }

    public function addEventCollection(EventCollection eventCollection)
    {
        this->eventCollection[] = eventCollection
    }
}

//Client
booking = new Booking('me', '[email protected]')
eventCollection = new EventCollection()->buildAvailableEvents()
booking->addEventCollection(eventCollection)

Is this conforming to any pattern? I feel I’m missing something due to the fact I’m just using objects as simplified holders of arrays of objects. Can this be refactored into any such patterns to reduce class bulk? I do see some duplication of code, but have simply refactored that within the same class.

I have tried to separate into single responsibilities.

Can anyone suggest any improvements? This isn’t operational code, I’ve just semi-stubbed it up.

1

Design patterns are “best practice” solutions for challenges that occur frequently when designing software. The benefit of design patterns lies in

  • If you find that your problem (nearly) fits a design pattern, you have a short name to call your problem by, which eases communication with others
  • The solutions presented in design patterns are generally well researched and the advantages, disadvantages, challenges in implementation and when not to use it are usually well documented.

On the other hand, design patterns do not and will never cover all aspects of a design. They are usually focused more on design challenges that have non-trivial solutions or trade-offs.
A composition of (collections of) classes as you show in your example is not described in any design pattern I know of. This is not bad and is most likely because it is not considered a big enough design challenge to justify the effort it takes to write a design pattern about.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật