Enviar pesquisa
Carregar
Scala as "Better Java" from object-oriented viewpoint
•
7 gostaram
•
2,279 visualizações
L
lyrical_logical
Seguir
http://www.scalaconf.jp/en/program/index.html#A15102
Leia menos
Leia mais
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 40
Baixar agora
Baixar para ler offline
Recomendados
[A3]deview 2012 network binder
[A3]deview 2012 network binder
NAVER D2
Patterns
Patterns
Michele Mondora
Chong Comparing Four E Learning Applications
Chong Comparing Four E Learning Applications
CISPI, STC Chicago, CCASTD, Roosevelt University
Adapter 2pp
Adapter 2pp
rajjani
The Forces Driving Java
The Forces Driving Java
Steve Elliott
Ruby On Rails pizza training
Ruby On Rails pizza training
david_alphen
Architecture | Modular Enterprise Applications | Mark Nuttall
Architecture | Modular Enterprise Applications | Mark Nuttall
JAX London
JDT Fundamentals 2010
JDT Fundamentals 2010
Olivier Thomann
Recomendados
[A3]deview 2012 network binder
[A3]deview 2012 network binder
NAVER D2
Patterns
Patterns
Michele Mondora
Chong Comparing Four E Learning Applications
Chong Comparing Four E Learning Applications
CISPI, STC Chicago, CCASTD, Roosevelt University
Adapter 2pp
Adapter 2pp
rajjani
The Forces Driving Java
The Forces Driving Java
Steve Elliott
Ruby On Rails pizza training
Ruby On Rails pizza training
david_alphen
Architecture | Modular Enterprise Applications | Mark Nuttall
Architecture | Modular Enterprise Applications | Mark Nuttall
JAX London
JDT Fundamentals 2010
JDT Fundamentals 2010
Olivier Thomann
BP203 limitless languages
BP203 limitless languages
Mark Myers
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
JAX London
Intel open mp
Intel open mp
Piyush Mittal
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm Server
Sam Brannen
What's Expected in Java 7
What's Expected in Java 7
Gal Marder
Greenplum Database on HDFS
Greenplum Database on HDFS
DataWorks Summit
Javascript training sample
Javascript training sample
prahalad_das_in
OSGi Best Practices - Tim Ward
OSGi Best Practices - Tim Ward
mfrancis
Tales About Scala Performance
Tales About Scala Performance
Haim Yadid
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
nick_garrod
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Kris Mok
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
Thomas Wuerthinger
Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages Toolchain
Attila Szegedi
Ruby
Ruby
Aizat Faiz
Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.
Gunnar Wagenknecht
Session 02 - Elements of Java Language
Session 02 - Elements of Java Language
PawanMM
Clean Code
Clean Code
Victor Rentea
Raphael Amorim - Scrating React Fiber
Raphael Amorim - Scrating React Fiber
React Conf Brasil
Dark side of the reflect
Dark side of the reflect
sairoutine
Writing Readable Code
Writing Readable Code
eddiehaber
Mais conteúdo relacionado
Semelhante a Scala as "Better Java" from object-oriented viewpoint
BP203 limitless languages
BP203 limitless languages
Mark Myers
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
JAX London
Intel open mp
Intel open mp
Piyush Mittal
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm Server
Sam Brannen
What's Expected in Java 7
What's Expected in Java 7
Gal Marder
Greenplum Database on HDFS
Greenplum Database on HDFS
DataWorks Summit
Javascript training sample
Javascript training sample
prahalad_das_in
OSGi Best Practices - Tim Ward
OSGi Best Practices - Tim Ward
mfrancis
Tales About Scala Performance
Tales About Scala Performance
Haim Yadid
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
nick_garrod
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Kris Mok
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
Thomas Wuerthinger
Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages Toolchain
Attila Szegedi
Ruby
Ruby
Aizat Faiz
Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.
Gunnar Wagenknecht
Session 02 - Elements of Java Language
Session 02 - Elements of Java Language
PawanMM
Clean Code
Clean Code
Victor Rentea
Raphael Amorim - Scrating React Fiber
Raphael Amorim - Scrating React Fiber
React Conf Brasil
Dark side of the reflect
Dark side of the reflect
sairoutine
Writing Readable Code
Writing Readable Code
eddiehaber
Semelhante a Scala as "Better Java" from object-oriented viewpoint
(20)
BP203 limitless languages
BP203 limitless languages
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
Intel open mp
Intel open mp
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm Server
What's Expected in Java 7
What's Expected in Java 7
Greenplum Database on HDFS
Greenplum Database on HDFS
Javascript training sample
Javascript training sample
OSGi Best Practices - Tim Ward
OSGi Best Practices - Tim Ward
Tales About Scala Performance
Tales About Scala Performance
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages Toolchain
Ruby
Ruby
Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.
Session 02 - Elements of Java Language
Session 02 - Elements of Java Language
Clean Code
Clean Code
Raphael Amorim - Scrating React Fiber
Raphael Amorim - Scrating React Fiber
Dark side of the reflect
Dark side of the reflect
Writing Readable Code
Writing Readable Code
Scala as "Better Java" from object-oriented viewpoint
1.
Scala as "Better
Java" from object-oriented viewpoint Shinya Mochizuki lepidum Co Ltd. 02 March 2013 https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
2.
About this talk
Main Topic Object-Oriented Programming No Functional Programming! https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
3.
Difficulty
Easy! But... Difficulty != Importance https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
4.
What is Scala?
FP + Traditional OO like Java FP + Improved OO compared to Java https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
5.
What is a
pretty program? Structured by reusable components. Components is expressed as Function, Class, Module, etc. In OO, a component is basically class. More precisely, class instances. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
6.
What is a
component? Structured by components. Mostly smaller. Component composition is expressed as “composition” != Composite Pattern (GoF) Function composition, Inheritance, Include, etc. In OO, composition is inheritance. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
7.
Implmentation inheritance
Component composition by OO feature. public class Logger {...} public class Counter extends Logger {...} public class Receptionist extends Counter {...} Problems Unintended polymorphism. Counter is not a Logger! Neither is Receptionist. Publishing implementation details. Receptionist inherits Counter and Logger public methods. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
8.
Lack of language
feature No multiple composition in Java e.g. Multiple inheritance like C++ https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
9.
Composition direction
Single inheritance Only vertically. Multiple inheritance Vertically and horizontally. But has some problems. e.g. conflict method resolution In Scala? https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
10.
Scala's feature: Traits
and mixin Traits are like Java's interfaces, but can contain arbitrary method implementations. Class/Trait can inherit from arbitrary trait. Inheriting traits is called “mixin”. Trait as component can be composed horizontally. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
11.
In Scala: Implmentation
mixin Using trait instead of class. trait Logger {...} trait Counter {...} class Receptionist extends Logger with Counter {...} Resolved Unintended polymorphism. Unresolved Publishing implementation details. Problems Each component is hard linked. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
12.
Lack of language
feature Implementation only Inheritance. Like private inheritance of C++. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
13.
Lack of language
feature causes... Repeated patterns. Like GoF's Design Patterns. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
14.
Aggregation (aka Composition)
Well-known alternative. public class Receptionist { private Logger logger = new Logger(); private Counter counter = new Counter(); ... } ● Resolved Publishing implementation details. Unresolved Each component is hard linked. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
15.
Hard linking problem
For a component to be reusable, it must: Remove hard links. Abstract dependencies (aka interface extraction). public interface ILogger {...} public interface ICounter {...} public class Logger implements ILogger {...} public class Counter implements ICounter {...} https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
16.
Dependency Injection (DI)
Pattern Well-known pattern in Java community. public class Receptionist { private ILogger logger; private ICounter counter; public Receptionist(ILogger logger, ICounter counter) {...} ... } Resolved Each component is hard linked. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
17.
Dependency Injection (DI)
Pattern Problems Wiring is too verbose. ILogger logger = new Logger(...); ICounter counter = new Counter(...); Receptionist receptionist = new Receptionist(logger, counter); Unclear dependencies between components. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
18.
Lack of language
feature Java dosen't have features for Expressing dependencies. Flexible composition. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
19.
Lack of language
feature causes... Work-around libraries/frameworks. DI Container frameworks provide it. e.g. Guice, Spring Framework, Seaser, etc. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
20.
Using DI Container
For example, in Guice public class Receptionist { @Inject private ILogger logger; @Inject private ICounter counter; ... } Resolved Unclear dependencies between components. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
21.
Using DI Container
Resolved Wiring (Composition) is too verbose. public class Module extends AbstractModule { @Override protected void configure() { bind(ILogger.class).to(Logger.class); bind(ICounter.class).to(Counter.class); } } https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
22.
Lack of language
feature causes... Createing some common patterns. Work-around libraries/frameworks. Scala has the features that Java lacks! https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
23.
Scala's feature: Self
type annotation Expressing dependencies class Receptionist { this: ILogger with ICounter => ... } Resolved Unclear dependencies between components. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
24.
Scala's feature: Self
type annotation Flexible composition. val receptionist = new Receptionist with Logger with Counter Resolved Wiring (Composition) is too verbose. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
25.
Self type annotation
vs DI Container Static vs Dynamic? Flexibility Static < Dynamic DI Container wins? But static methods can compound dynamic methods. To be precise, Static + Dynamic vs Dynamic! Static + Dynamic > Dynamic https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
26.
Is self type
annotation perfect? No, unfortunately it is not... https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
27.
Fibonacci number
Easy and simple example. public class Fib { int fib(int n) { if (n <= 1) return n; else return fib(n – 1) + fib(n – 2); } } https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
28.
Extend Fib
Memoization, easy. public class MemoFib extends Fib { private Map<Integer, Integer> tbl = new HashMap<Integer, Integer>(); @Override int fib(int n) { if (tbl.containsKey(n)) return tbl.get(n); int result = super.fib(n); tbl.put(n, result); return result; } } https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
29.
Extend Fib
Logging, easy. public class LogFib extends Fib { @Override int fib(int n) { System.out.println(“Entering fib(“ + n + “)”); int ret = super.fib(n); println(“Exiting fib(“ + n + “) = “ + ret); return ret; } } https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
30.
Combination explosion
Combine extension features. public class MemoLogFib extends LogFib {...} public class LogMemoFib extends MemoFib {...} Problems Each component is hard linked. Code duplication. Code of MemoFib and MemoLogFib are duplicated. The same is true for LogFib and LogMemoFib. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
31.
Decorator pattern (GoF)
Specialized DI Pattern. public interface IFib {...} public class Fib implements IFib {...} public class MemoFib implements IFib {...} public class LogFib implements IFib {...} Resolved Each component is hard linked. Code duplication. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
32.
Decorator pattern (GoF)
Problems Composition is too verbose. IFib fib = new MemoFib( new LogFib( new Fib() ) ) https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
33.
Try to apply
self type annotation The result ... ? class Fib extends IFib {...} trait MemoFib extends IFib { this: IFib => def fib(n: Int) = ... // how to refer composited fib? } new Fib with MemoFib // oops, error! Lacking override modifier Problems Can not refer to its own required components. Can not composit components. The Cause Provided and required components are same. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
34.
Scala's feature: Abstract
override Modifier for overriding abstract method. trait LogFib extends IFib { abstract override def fib(n: Int): Int = { println(s“Entering fib($n)”) val ret = super.fib(n) println(s“Exiting fib($n) = $ret”) ret } Resolved Can not refer to its own required components. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
35.
Scala's feature: Abstract
override Flexible combination with mixin. new Fib with LogFib with MemoFib fib 42 new Fib with MemoFib with LogFib fib 42 Resolved Combination is too verbose. Can not composit components. Improved Resolving abstract method at composition timing. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
36.
Summary of Scala's
OO features Traits and mixin provides flexible component composition. Self type annotation expresses required other components. Abstract override refers to abstract methods by super. can handle some corner case of self type annotation. provided and required component are same. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
37.
Benefities of the
language support Patterns can resolve problems, but... Mostly verbose. Need for common language. ● Frameworks can resolve problems, but... A little verbose compared with language feature. Sometimes too large. Language support needs for reusability, readability and writability. https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
38.
Scale, Scale, Scale!
Out of scopes Sealed modifier, case class, pattern match and extractor As (G)ADTs and pattern match (Abstract) type member Structural subtype Implicit conversion and view bounds Implicit parameter and context bounds As type classes Path/method dependent types Etc... https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
39.
Q&A
Any questions? https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
40.
Thanks
Scale Your Programming! https://lepidum.co.jp/ Copyright © 2004-2013 Lepidum Co. Ltd. All rights reserved.
Baixar agora