Coder Social home page Coder Social logo

advanced-java-20121029's Introduction

Advanced Java, October 29-31 2012

Class Videos

Day 1:

Day 2:

Day 3:

Contracts and Inheritance

Liskov Substitutability Principle (LSP)

  • Given a Base and Derived class, a program that works with the Base class should also work with the Derived class.

Specification-based testing

  • establish invariants (contracts) and assert that those invariants hold for all possible arbitrary sample data

Value Classes vs. Service Classes

  • Value classes have structural identity, final fields, getters. They shouldn't have anything else (no other methods), otherwise you end up with unnecessary coupling in your architecture.
  • Service classes usually only have reference identity, and mutable state.

Object Identity

  • Referential Identity: determined uniquely by address in memory, e.g. a == b
  • Structural Identity (or "Value" Identity): determined by an object's properties, e.g. a.equals(b)
  • Only use immutable fields to determine structural identity

Immutability

Benefits

  • Fewer tests
  • Less code
  • Correct code
  • Safe inheritance (code reuse)
  • Stable object identity
  • Obviates need for synchronization, resulting in correct, high performance concurrent code
  • Encourages sharing (memory efficiency. See Okasaki, "Purely Functional Data Structures." e.g. finger trees, hash array mapped tries)

Resource Management

  • Any time a resource is allocated or obtained, you must try/finally immediately afterwards to close the resource (Java 6), or use a try-with-resources block (Java 7).

Design Patterns

  • Composite: multiple implementations of a common interface, some of which may recursively contain instances of the interface. Example: expressions with sub-expressions in a parse tree.

  • Visitor: avoid polluting a composite (above) data structure with orthogonal concerns. Define a "Visitor" interface with visit() methods for each composite implementation case, and define an accept() method in the composite interface which takes a visitor. Example: multiple serializers and evaluators for expressions.

  • Producer-Consumer: implement concurrent programs as a set of producers which push messages to a queue, and consumers which pop messages from the queue. Use java.util.concurrent.BlockingQueue to implement this cleanly, and avoid explicit synchronization.

  • Builder: start with an empty "builder" object, and chain method calls to append/set properties on it.

  • Decorator: wrap a class that implements low-level functionality in another class that implements additional higher-level functionality. Example: java.io.*

advanced-java-20121029's People

Contributors

mergeconflict avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.