A tuple is an ordered, immutable list of elements. Groovy has it's own groovy.lang.Tuple class. We can create an instance of a Tuple by providing all elements that need to be in the Tuple via the constructor. We cannot add new elements to a Tuple instance or remove elements. We cannot even change elements in a tuple, so it is completely immutable. This makes it very useable as return value for a method where we need to return multiple values. Groovy also provides a Tuple2 class that can be used for tuple instance of only two elements. The elements are typed in a Tuple2 instance. def tuple = new Tuple ( 'one' , 1 , new Expando ( number : 1 ) ) assert tuple . size ( ) == 3 // To get the value of an element // at a certain position we use // the get(index) method. assert tuple . get ( 0 ) ==...
Dependency Injection In Spring DI Basics • Reduces coupling between classes • Classes do not obtain their dependencies (collaborators), Spring container provides proper dependency based on configuration provided • Enables easy switching of dependencies based en current needs - local development vs production environment, easy mocking for unit tests, in memory database vs production one, etc. • Promotes programming to interfaces • Spring-managed objects are called "beans" • Beans are written as POJOs, no need to inherit Spring base classes or implement spring interfaces • Classes can be completely independent of Spring framework (although for convenience Spring annotations are often used) • Lifecycle of beans is managed centrally by Spring container (eg. enforces singleton state of bean/ one instance pers session. one instance per HTTP request/...) • Spring configuration (including DI) is possible either via XML or Java configuration files (newer, more popular approac...
Comments
Post a Comment