Thursday, 14 April 2022
Sunday, 16 January 2022
Recently we got a requirement to an existing product and which have some legacy implementation too. Here the requirement to have a FAB (Chat Bot) action to be available on all the application screens (Activity).
Discussion where went like below:
1. Adding FAB to all the activity is a very tedious process, even creating a common layout and add using <include> in all layout also not that simple task. 😟 (Bad Practice too)
2. Will create a simple FAB Action class and planned to initialize it in all the activity class, since it is also a required some more efforts to update the initialization code in all the activity classes. (This implementation will reduces the effort but not fully, It helps to update on our Common BaseActivity and few other independent Activities by doing the initialization) 😌
3. Finally Achieved!.. Implemented through Application class and ActivityLifecycleCallbacks, which made the implementation easier to work seamlessly across the application. 😎
Saturday, 25 December 2021
In object-oriented programming, delegation refers to evaluating a member (property or method) of one object (the receiver) in the context of another original object (the sender).
Delegation is a design pattern in which an object handles a request by delegating to a helper object, called the delegate. The delegate is responsible for handling the request on behalf of the original object and making the results available to the original object.
Kotlin supports “delegation” design pattern by introducing a new keyword “by”. Using this keyword or delegation methodology, Kotlin allows the derived class to access all the implemented public methods of an interface through a specific object
Delegation should be used when:
- When your subclass violates the Liskov substitution principle. For example, when we are dealing with situations where inheritance was implemented only to reuse code of the superclass, but it is not really acting like it.
- When the subclass uses only a portion of the methods of the superclass. In this case, it is only a matter of time before someone calls a superclass method that they were not supposed to call. Using delegation, we reuse only methods we choose (defined in the interface).
- When we cannot or we should not inherit, because:
- The class is final
- It is not accessible and used from behind interface
- It is just not designed for inheritance
Saturday, 13 November 2021
Vetoable, this allows us to modify the values when the argument input by the user(s) fulfills the specified condition, it can be used in place of observable properties if the user wants to intercept assignment. Vetoable is like Observable Properties with additional features to allows to modify and notify the values when the condition is met.
The string which you never want to be reassigned with empty or to some specific text.
The number values which is assigned should be match some condition.
The generic observable kind of where the condition check will happen and then the value will be get assigned to the variable, incase if the condition fails, older value will be retained.
Sunday, 17 October 2021
This provides safe access to elements of a collection. It takes an index and a function that provides the default value in cases when the index is out of bound.
This returns the value of the key. If the key is not found in the map, calls the default value function, puts its result into the map under the given key and returns value of the same.
Sunday, 26 September 2021
associateBy and groupBy function helps to build the maps from the elements of a collection indexed by the specified key.
keySelector: The key is defined in the keySelector parameter.
valueSelector: We can also specify an optional valueSelector to define what will be stored in the value of the map element, in case of not specifying the same it will consider the complete object as a value.
The difference between associateBy and groupBy is about how they process the objects with the respective key
associateBy - It uses the last suitable element as the result value.
groupBy - it produces the list of all suitable elements and puts it in the result value(s).
P.S. The returned map preserves the entry iteration order of the original collection.
Sunday, 12 September 2021
We should use DSL to simplify and improve the complexity of the app and make the code more readable, Before jumping into writing our own DSL we need to aware about the concept of lambda with receiver, invoke and operator.
Assume an example we have a class called Device, Please see below different ways how the object got initialized
Now, to instantiate the Class we can create an object like below ways,