Download presentation
Presentation is loading. Please wait.
Published byBrianne Brown Modified over 8 years ago
1
Design I
2
Properties of good design Minimize complexity Maintainable Loose coupling Extensibility Reusability High fan in Low to medium fan out Portability Leanness Stratification Standard techniques
3
Some principles of good design Open-Close Principle Dependency Inversion Principle Interface Segregation Principle Single Responsibility Principle Liskov’s Substitution Principle
4
Design heuristics 1.Use real-world and synthetic objects a)identify objects & their attributes b)determine relationships c)how they interact to realize use cases 2.Refine your classes based on responsibilities 1.don’t let an class do too much 2.keep it cohesive 3.identify areas of potential change
5
Example I am developing software that (among other things) displays geometric primitives Initially I only need to support lines In the future I may need to add spheres, triangles, and squares Rather than reinvent the wheel, I am going to use an existing program. Actually, I really want the option of choosing at run time between two different drawing programs, one that is better at low resolutions and one that is better at high resolutions
6
current design shape line draw()
7
Drawing APIs Package 1: drawLine(x1, y1, x2, y2) Package 2: drawALine(x1, x2, y1, y2)
8
solution 1 line.draw() { if (resolution == high) drawLine(v1.x, v1.y, v2.x, v2.y) else drawALine(v1.x, v2.x, v1.y, v2.y) }
9
solution 1 AdvantagesDisadvantages
10
solution 1 Advantages –simple to implement –simple to understand Disadvantages –is knowing about resolution really a responsibility of shape? –we are duplicating code
11
Some principles of good design Open-Close Principle Dependency Inversion Principle Interface Segregation Principle Single Responsibility Principle Liskov’s Substitution Principle No forgery principle (keep data in a single place) One rule one place (don’t duplicate code)
12
solution 2 line lineDP1lineDP2
13
solution 2 Advantages –simple to implement –simple to understand Disadvantages –as additional shapes and drawing programs are added the number of classes becomes LARGE
14
Shape TriangleLine Drawer Low ResHi Res Bridge design pattern defines the interface shapes use to draw “adapters” for specific drawing interfaces
15
Bridge Problem: Want to support multiple implementation that have different interfaces in an extensible way.
16
Last time Choose a game loop at some specific part of your (core) game Develop a domain model –what are the things (nouns) –what are their relationships Develop your game loop use case Use CRC cards to come up with a first pass at your design Act out the game loop use case
17
This time Critique your design –based on design principles –properties of good design –design heuristics Report to class
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.