khaledmohamedadelkam
11 views
57 slides
May 07, 2024
Slide 1 of 57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
About This Presentation
Design patterns
Size: 15.56 MB
Language: en
Added: May 07, 2024
Slides: 57 pages
Slide Content
Design Patterns Khaled kamara
Software crisis How to be a better developer Solving A problem What and why Design patterns Let’s code a game together What else How can you select the right design pattern Some useful Design patterns for Graduation project Architectural Pattern Snap on software Architecture Table of Content
Software crisis Most software projects fail completely or partially because they don’t meet all their requirements. These requirements can be the cost, schedule, quality, or requirements objectives. According to many studies, the failure rate of software projects ranges between 50% – 80% .
Data structure Software engineering Design Principles & Solid Modern Architecture Clean Code & Code Complexity Best Practice&Generics Design patterns
Patterns is everywhere
Let’s make the Balloon Float
What is Design patterns A standard solution to a common software problem in a context. describes a recurring software structure or idiom is abstract from any particular programming language identifies classes and their roles in the solution to a problem Same problem Different implementation
Benefits of using Design patterns Patterns give a design common vocabulary for software design: Allows engineers to abstract a problem and talk about that abstraction in isolation from its implementation. A culture; domain-specific patterns increase design speed. Capture expertise and allow it to be communicated: Promotes design reuse and avoid mistakes. Makes it easier for other developers to understand a system. Improve documentation (less is needed): Improve understandability (patterns are described well, once). The change is the only fact
GOF in 1990 a group called the Gang of Four or "GoF" (Gamma, Helm, Johnson, Vlissides) compile a catalog of design patterns 1995 book Design Patterns: Elements of Reusable Object-Oriented Software is a classic of the field
Singleton intent : Ensure a class has only one instance and provide a global point of access to it Problem : How can we guarantee that one and only one instance of a class can be created Solution
Game Story A game of a fighter walking in Road, facing random enemies, Finding New Weapons and health potions.You can choose different culture (pharos, bableons, Grease). In case Fighter got spelled, it will affect his speed Very slow or very fast. Fighter has one check point in the middle of every level to save his state, to return any time he want. Every level up upgrade age(Stone age, Iron Age).
fighter E nemies culture Potions Level up restart level Checkpoint Spells New ages Key Words
To create fighter you need to go throw the fighter wizard in which you can choose Fighter gender and type. every user has 1000 Coin you can purchase weapon and armor that affect can increase health or strength fighter
Builder
Intent construct complex objects step by step. Also allows you to produce different types and representations of an object using the same construction code . Problem step-by-step initialization of many fields and nested objects. Such initialization code is usually buried inside a monstrous constructor with lots of parameters. Or even worse: scattered all over the client code . Solution: Builder
We have many enemies in the game with different types and power. Each level can has certain number of each enemy Enemies
Factory
Intent Creating complex object by the simplest way,encapsulate whats vary or adding logic to creation. Problem Creating the object is different or expensive, repetitive code, Solution: Factory
We have many culture supported, Culture is a theme for the fighter , enemies, weapons, armos, flags and colors Culture
Bridge
Intent split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other. Problem Merging classes can be messy Solution: Bridge
Fighter can find Potions that improve his strength or Armor Potions
Decorator
Intent Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. Problem Imagine that you’re working on a notification library which lets other programs notify their users about important events. Solution: Decorator
To restart level or to create new level we have many steps, Like creating new enemies, loading Page celebrate if new level , say ooh if restart level ...etc Level Up
facade
Intent provides a simplified interface to a library, a framework, or any other complex set of classes,User does not need to know all our steps, just want my app to work Problem Functions can vary,can be from different source Solution: facade
The Game has many check point, when the user reach it he can save the state ,in case he lost his live or close the game he can come back to this point Save CheckPoint
Memento
Also known as: Snapshot Intent save and restore the previous state of an object without revealing the details of its implementation. Problem Want to come Back to the old State,simplest way. Solution: Memento
Enemies can cast Spells on our fighter, that can affect fighter speed Spells
State
Intent lets an object alter its behavior when its internal state changes. It appears as if the object changed its class . Problem The main idea is that, at any given moment, there’s a finite number of states which a program can be in. Within any unique state, the program behaves differently, and the program can be switched from one state to another instantaneously. Solution: State
Every Level Introduce a new Age, Every Age Steps work in a different way to create a unique Game Board , Enemies ,weapons, armors and potions Introduce New Age
Template
Intent defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. Problem To handle the code in a different way, system will need to create a lot of classes that will be redundant Solution: Template
Do not overuse the patterns Overusing the patterns,can Complicate our Code. One million dollar Pen In the cold war between america and russia there was a space war, astronauts needed pens to write, american scientist invented a pen that cost million dollar. While russian write in pencil CarGo Cult Programming
Identify the problem Review the existing patterns Evaluate the pros and cons Apply the pattern How can you select the right design pattern for your project? We can use part of design pattern to solve the problem or combine between them.
Are there more design patterns than the 23 of Gang oF four?
The fact that GoF realized the power of the pattern language, and wrote the first book does not limit the patterns to the 23. patterns is a very rich subject and not limitative to any list provided by any single individual. Are there more design patterns than the 23 of Gang oF four?
T here are plenty of other pattern repositories. As example, there are Martin Fowler’s (more than 50) patterns of enterprise application architecture , which are -despite their name- also design patterns. There are several other repositories and books that describe either general patterns or domain specific patterns, like for example for the gaming industry .
You can try to invent one yourself as an academic exercise, but as this answer already suggests, the best way to uncover these patterns is to find a bunch of seemingly unrelated problems that have a common solution. That common solution becomes the design pattern. How do we find new patterns? For example, the ( Josh Bloch builder pattern (not to be confused with the Gang of Four's builder pattern )) arose out of the need for a readable way to initialize an object with a large number of parameters, and was heavily influenced by another design pattern, the fluent interface/API .
MVC Generic /regular Repository Unit of work Dependency Injection Pattern Circuit Breaker Command and Query Responsibility Segregation (CQRS) Event Sourcing Sidecar Backend-for-Frontend Strangler Modern-Day Design Patterns Some useful Design patterns for Graduation project
What is MVC Model View Controller Is it a pattern? All architectural patterns are design patterns, but not all design patterns are architectural. it's called architectural when its high level pattern chosen in the application design phase. MVC
An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context. Architectural patterns are similar to software design pattern but have a broader scope. Most Common MVC MVP MVVM CQRS Architectural Pattern
Architecture Vs Architecture Pattern VS Design pattern
Software as a service MicroServices Onion Architecture Clean Architecture N-Tire ( Layered Architecture ) Serverless Architecture Event-Driven Architecture (Event Sourcing) Domain Driven Design (DDD) Some Software Architectural
Design Principles samples
Anti Patterns
Anti-patterns are the opposite of best practice, which is a solution that has been proven to be effective. They are often used because they seem to work, but the larger context or the long-term consequences are often not considered. They can occur in : software design project management organizational behavior. We should avoid Anti-Patterns Anti-Patterns
common mistakes or poor practices when writing source code. That can lead to problems like increased complexity and reduced maintainability. Spaghetti Code Boat anchor /Lava Flow Accidental Complexity God Object Hard Code / soft Code Mag ic (Numbers /Strings) Golden hammer Dead Code CarGo Cult Programming Single function exist point Programming Anti-patterns