1 of 18

� � CMP-3110 ~ E-Commerce Applications Development

Lecture 02

Planning Our Framework

2 of 18

Framework

  • Definition
    • a basic structure underlying a system, concept, or text.
    • In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful.

​

3 of 18

Patterns

  • Definition
    • a design pattern is a general repeatable solution to a commonly occurring problem in software design.
    •  A design pattern isn't a finished design that can be transformed directly into code
  • Uses of Design Patterns
    • speed up the development process
    • providing tested, proven development paradigms

​

4 of 18

Patterns

Which patterns will be used?

  • Model-View-Controller (MVC)
  • Registry
  • Singleton

5 of 18

Model-View-Controller (MVC)

  • Model 
    • Represents an object. It can also have logic to update controller if its data changes.
  • View 
    • Represents the visualization of the data that model contains.
  • Controller 
    • Acts on both model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps view and model separate.

6 of 18

Model-View-Controller (MVC)

7 of 18

Model-View-Controller (MVC)

8 of 18

Model-View-Controller (MVC)

Reference: Software Engineering by Ian Summerville – 9th edition

9 of 18

Registry

  • Provides a means to store a collection of objects within our framework (Container of objects for reuse).

​

  • Each set of controllers and models we create need to perform some shared tasks, including:
    • Querying the database
    • Checking if the user is logged in, and if so, getting certain user data
    • Sending data to the views to be generated (template management)
    • Sending e-mails, for instance to confirm a purchase with the customer
    • Interacting with the server's filesystem, for instance to upload photographs of products

​

10 of 18

Registry

11 of 18

Singleton

  • Restrict an object to one instance only

​

  • However, we will use it to ensure we have only one instance of our registry available in the framework at any point of time.

12 of 18

File/Folder Structure

13 of 18

Building a Framework

14 of 18

Pattern Implementation: MVC

15 of 18

Pattern Implementation: Registry�

  • Needs
    • It needs to have a method to create certain objects and store them with a key.
    • It needs another method, which when passed with a key as a parameter, returns the object in question.
  • working
    • Processing the incoming URL, so our “index.php” file can route the request correctly
    • Building URLs based on a series of parameters, a query string, and the URLdisplay/generation method we use
    • Pagination

16 of 18

Pattern Implementation: Registry�

  • The code in the book makes up the basics of our registry, with two arrays:
    • One for objects
    • One for settings

​

​

17 of 18

Pattern Implementation: Singleton�

  • The singleton pattern is very easy to implement, as it requires only a few minor changes to a standard PHP class, to ensure that it is only ever instantiated once.
  • Needs
    • A private constructor is used to prevent the direct creation of objects from the class.
    • The expensive process is performed within the private constructor.
    • The only way to create an instance from the class is by using a static method that creates the object only if it wasn't already created.

​

18 of 18

Routing requests