php egypt jan14

16
Why & How to make your own framework Why & How to make your own framework تقديم هاني جمالPHP Egypt كتب إطار عملذا و كيف ت لماكتب إطار عملذا و كيف ت لما پ ي اتش پ ي مص برعاية

Upload: hani-gamal

Post on 09-Aug-2015

374 views

Category:

Documents


2 download

TRANSCRIPT

Why & How to make your own frameworkWhy & How to make your own framework

تقديمهاني جمال

PHP Egypt

لماذا و كيف تكتب إطار عمللماذا و كيف تكتب إطار عمل

مصيپ اتش يپ

برعاية

ما هو إطار العملما هو إطار العمل

A collection of software libraries providing a defined application programming interface (API).

(API) is a specified source code to be used as a communication interface between software components.

The (API) includes specifications for routines, data structures, object classes, and variables.

What is a framework What is a framework

And I Say ...

✔ The Software Framework is about finding common solutions for difficult problems”

?Why لماذا؟

Security MattersSecurity Matters It is secured because you made it

LicenseLicense To define your own license

Practice not to use but to learn :)Practice not to use but to learn :) Improves lack-of-time decision making Thinking in terms of API improves code quality

Great AssetGreat Asset Reusable things are corporate assets

استراحة للمناقشة

مباديء و معايير عامة

Good code is modular Easy to read, to learn and to use Hard to misuse Can meet requirements Easy to extend

مباديء و معايير عامة

Focus on gathered requirements Extract the true requirements use-casesuse-cases Build general & generic Code lives on as examples and unit tests Build a Service Provider Interface (SPI) Make sure that better solutions exists Expect to make mistakes

مباديء و معايير عامة

Your API should do one thing and do it well Functionality should be easy to explain Should be as small as possible but not smaller You can always add but you can never remove API is a little language, so be consistent, regular

and strive for symmetryif (car.speed() > SPEED_LIMIT) createAlert(”Watch out for cops!”);

””You'll either step forward in growth or will You'll either step forward in growth or will step back into safety” --Abraham Maslowstep back into safety” --Abraham Maslow

مباديء و معايير عامة

Implementation should not impact API Ex. don't specify hash functions

Minimize accessibility of everything Make classes and members as private as

possible Public classes should have no public fields

except the constants This maximizes information hiding and allows This maximizes information hiding and allows

modules to be used, understood, built, tested and modules to be used, understood, built, tested and debugged independentlydebugged independently

مباديء و معايير عامة

Reuse is easier to say then to do Reuse = Good Design + Very Good Documentation

Document every class, interface, method, constructor, parameter and exception

Obey standard naming conventions Return types and avoid obsolete parameters Simulate patterns of the language

Class Design

Simple Thread-safe Reusable

Class Design

Subclass only when it makes sense otherwise use composition

Public classes should not subclass other public classes for ease of implementation

””if you allow subclassing, how do methods if you allow subclassing, how do methods use one another?”use one another?”

Method Design

Don't make the client do anything the module could do

Reduce the need for copy-paste Strong typing is the best Provide programmatic access to all data

available in string form Clients should never parse strings

Overload carefully

Method design

Use appropriate parameter and return types

Don't use string if a better type exists

Don't use floating point for monetary values Binary floating causes inexact results!

Use double(64 bits) instead of float(32 bits)

Use consistent parameter ordering across methods

Avoid long parameter list, three or less :)

Avoid return values that demand exceptional processing

Exception Design

Throw exceptions to indicate exceptional conditions only!

Don't force client to use exceptions for control flow!

Do silent exceptions so client won't be forced to take a recovery action

Include failure-capture information in exceptions to allow providing repair or recovery

شكرًا