Grails Flashcards
(21 cards)
Java Bean
A Java Bean is a class that fulfills three criteria:
- All properties are private (accessed via getters/setters)
- Constructor is public and has no arguments
- Implements Serializable (so returned objects can be serialized)
AST Browser
A Groovy tools that allows you to see how your code is compiled (parsing, conversion, semantic analysis, etc)
JD-GUI
A tool that allows you to decompile your .class files to see what was added to them
Closure
- A function written inside another function that has access to the outer function’s scope
- A closure “saves” the outer functions local variables, and if the closure is returned when the outer function is run, it will still have access to the outer function’s scope even though the outer function has finished running
Abstract Class
A class high up in the hierarchy that defines variables and methods that should be present in each of its children, but leaves it up to the children to define those methods.
It guarantees that the children have a common set of variables and methods that are necessary for those children to communicate with one another (think of it as a common language among the children)
Interface
Similar to Abstract Class, but:
- Two objects to not need to be related to implement the same interface - common language among non-related classes
- Interfaces are “stricter” - they can only have final variables and abstract methods. Abstract classes can have abstract methods, concrete methods
- A class can implement multiple interfaces, whereas it can only extend from one class
void
Indicates that method does not return anything
Autoboxing and unboxing
Converting a primitive value into an object of the corresponding wrapper class is called autoboxing. It occurs if you assign an primitive to variable of the wrapper class, or if you pass a primitive into a function that expects the wrapper class.
Unboxing converts it back to the primitive type, and occurs in the reverse scenarios described above
Access Modifiers
Private - only same class can access Default - only classes in the same package can access Protected - Default + subclasses in a different package Public - Everybody get's a variable! You get a variable..
Overloading
Having the same method but with different, but using different parameters to create different method signatures. When calling the method, the method with the same number and data type positioning in the arguments will be called
Null-safe Deference
In Java, person.organization.name will throw a null pointer exception if organization is not defined. However, person?.organization?.name will return null and your code can procede
Elvis Operator
String name = person.name ? person.name : default name is equivalent to String name = person.name ?: default name
Singleton
A class that instantiates only one object at a time. You cannot create two instances of a Singleton to get two different resulting children
Views are located…
In grails-app/views
Angular Controllers are located…
In grails-app/assets/javascripts/angular-modules
URL Mapping is located…
In grails-app/conf/UrlMappings.groovy. However, by default, grails will look at the path of the URL and look for a controller class that matches that path, with “Controller” appended to the end of it
Services are located…
In grails-app/services. To create a service, just create a class in the grails-app/services directory, and append “Service” to the end of the class name.
Transactional Services
By default, all Services in Grails are considered transactional, meaning they have the necessary support to communicate with the database
Domain Classes
Domain Classes are located in the grails-app/domain directory. The class name maps to a database table name, and the field names map to database field names. For both, camelcase is converted to snakecase. Any field that is not scoped (public, private, protected, etc.) is assumed to be a database field name
How to inject a Spring Bean
Spring Beans are public, so all you need to do is call the bean by name and set it to a variable scoped to your class. For example, if you wanted to inject the user service spring bean into your class, write the following:
private Object userService void setUserService(Object userService) { this.userService = userService }
@Transactional tag
A Spring annotation that defines whether the class method (and the methods it calls) are part of a transaction. It also allows you to define aspects of the transaction - read only, timeout, rollback rules, etc