Top Banner
By Barak Drechsler Front End Component Based Architecture
18

Component Based Architecture

Feb 21, 2017

Download

Technology

Barak Drechsler
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Component Based Architecture

By Barak Drechsler

Front EndComponent Based Architecture

Page 2: Component Based Architecture

At the beginning we had MVW

MVC MVVM

Page 3: Component Based Architecture

How MVW front end apps looked like?

We would have a separate horizontal layers

VIews

Controllers

Models

Routes which linked between controllers and views.

Page 4: Component Based Architecture

Angular 1.4 app example MVC style

https://github.com/angular/angular-phonecat/tree/1.4-snapshot

Page 5: Component Based Architecture

But after a while things got complicated...

Hard to re-use

Hard to decouple

Hard to maintain and understand as the project grows

Models got bloated with view data.

Page 6: Component Based Architecture

And then...

Page 7: Component Based Architecture

Component Based Architecture

Component-based software engineering, is a branch of software engineering that emphasizes the separation of concerns in respect of the wide-ranging functionality available throughout a given software system. It is a reuse-based approach to defining, implementing and composing loosely coupled independent components into systems. This practice aims to bring about an equally wide-ranging degree of benefits in both the short-term and the long-term for the software itself and for organizations that sponsor such software. (wikipedia)

Page 8: Component Based Architecture

Component Definition

An individual software component is a software package, a web service, a web resource, or a module that encapsulates a set of related functions (or data).

(wikipedia)

Page 9: Component Based Architecture

Front End Component

Components only control their own View and Data

Components have a well-defined public API - Inputs and Outputs

Components have a well-defined lifecycle

(angular component doc)

Page 10: Component Based Architecture

The advantages of CBA

Vertical alignment of our code base

Advocates Unidirectional data flows

Easier separation of concerns, and single responsibility

Easier to maintain and expand

Reusability

Page 11: Component Based Architecture

CBA Example - angular 2 example app

https://github.com/johnpapa/angular2-tour-of-heroes

Page 12: Component Based Architecture

How to think in components?

Everything is a component, even if it won’t be reusable.

The whole app is a tree of components

Components contain other components

Components interact with other components through their defined API

Page 13: Component Based Architecture

Stateful and stateless components

Stateful - a “living” component which has knowledge and state, and the ability to modify state, and communicate with external resources.

Stateless

Receives inputs and displays them

Calculates changes, but do not store them, but transfer them to other components

Page 14: Component Based Architecture

Stateful - impure function

Page 15: Component Based Architecture

Stateless - pure function

Page 16: Component Based Architecture

Component Composition

Just like high order functions, we can composite components to extend and enhance existing components.

Usually stateful component will composite state less components to pass them data.

Page 17: Component Based Architecture

Components In action

Page 18: Component Based Architecture

Questions?