Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to be a Good Developer

Similar presentations


Presentation on theme: "How to be a Good Developer"— Presentation transcript:

1 How to be a Good Developer
SESSION 1

2 Values Simplicity Communication Feedback Courage Respect

3 Principles Boy Scout Rule Persistence Ignorance You Aren’t Gonna Need It Keep It Simple Stable Dependencies Hollywood Single Responsibility Open-Closed Liskov Substitution Interface Segregation Don’t Repeat Yourself Inversion of Control Dependency Inversion Explicit Dependencies Once and Only Once Separation of Concerns Tell, Don’t Ask Encapsulation Principle of Least Surprise

4 Patterns | Creational, Structural, Behavioural
Factory method Decorator Mediator Abstract factory Façade Memento Builder Flyweight Observer Prototype Proxy State Singleton Chain of responsiblity Stategy Adapter Command Template Bridge Interpreter Visitor Composite Iterator

5 Value | Simplicity We will do what is needed and asked for, but no more. This will maximize the value created for the investment made to date. We will take small simple steps to our goal and mitigate failures as they happen. We will create something we are proud of and maintain it long term for reasonable costs.

6 Value | Simplicity Pass all tests Express the author’s ideas Avoid duplication Minimise the number of classes, methods, and modules

7 Principles | Boy scout rule
“Always leave the campground cleaner than you found it." or “Always check code in cleaner than when you checked it out."

8 Principles | Persistence Ignorance
Classes which model business logic shouldn’t be affected by or designed for persistence logic

9 Principles | Persistence Ignorance
// logic to update an address mixed with database code trx = connection.CreateTransaction(); query = connection.CreateQuery("Select * from Employee where id = empid"); resultset = query.Run(); resultset.SetValue("Address_Street", "Bahnhofstrasse"); resultset.SetValue("Address_City", "Zürich"); trx.Commit();

10 Principles | Persistence Ignorance
void MoveToZuerichBahnhofstrasse(Employee emp) { // doesn't have anything to do with persistence emp.Address.Street = "Bahnhofstrasse"; emp.Address.City = "Zürich"; }

11 Pattern | Factory method Creational
Creating an instance of an object can sometimes require a lot of work and processes which might not always be the right thing to do or provide the best structure to overall code. Instantiation might lead to duplicated code Might require information not available to the object Might not be part of the object’s concerns

12 Pattern | Factory method Creational
Defines an interface for creating an object, but lets classes that implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.

13 Pattern | Factory method Creational
public abstract class MazeGame { private final List<Room> rooms = new ArrayList<>(); public MazeGame() { Room room1 = makeRoom(); Room room2 = makeRoom(); room1.connect(room2); rooms.add(room1); rooms.add(room2); } abstract protected Room makeRoom();

14 Pattern | Factory method Creational
public class MagicMazeGame extends MazeGame { @Override protected Room makeRoom() { return new MagicRoom(); } public class OrdinaryMazeGame extends MazeGame { return new OrdinaryRoom();

15 Pattern | Factory method Creational
MazeGame ordinaryGame = new OrdinaryMazeGame(); MazeGame magicGame = new MagicMazeGame();

16 Pattern | Factory method Creational
Source Making : Factory Method Design Pattern Wikipedia: Factory Method Pattern Binpress: The Factory Design Pattern Explained By Example

17 Pattern | Abstract factory Creational
Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

18 Pattern | Abstract factory Creational

19 Pattern | Abstract factory Creational
public abstract class CPU { } // class CPU class EmberCPU extends CPU { ... } // class EmberCPU class EmberToolkit extends ArchitectureToolkit { public CPU createCPU() { return new EmberCPU(); } // createCPU() public MMU createMMU() { return new EmberMMU(); } // createMMU() } // class EmberFactory

20 Pattern | Abstract factory Creational
public abstract class ArchitectureToolkit { private static final EmberToolkit emberToolkit = new EmberToolkit(); private static final EnginolaToolkit enginolaToolkit = new EnginolaToolkit(); ... // Returns a concrete factory object that is an instance of the // concrete factory class appropriate for the given architecture. static final ArchitectureToolkit getFactory(int architecture) switch (architecture) case ENGINOLA: return enginolaToolkit; case EMBER: return emberToolkit; } // switch } // getFactory() public abstract CPU createCPU(); public abstract MMU createMMU(); } // AbstractFactory public class Client public void doIt() AbstractFactory af; af = AbstractFactory.getFactory(AbstractFactory.EMBER); CPU cpu = af.createCPU(); } // doIt } // class Client

21 Pattern | Abstract factory Creational
Source Making : Abstract Factory Design Pattern Wikipedia: Factory Method Pattern Binpress: The Factory Design Pattern Explained By Example

22 Next session Value | Communication Principles | You Aren’t Gonna Need It Principles | Keep It Simple Patterns | Builder Patterns | Prototype


Download ppt "How to be a Good Developer"

Similar presentations


Ads by Google