Effective application analytic

  • Provide strict relation between categories, actions, labels and values. Thus, the probability of sending inconsistent analytics will be reduced to minimum
  • Provide api layer between usage of analytics and sending it. Thus, we will able to write tests for it, and check does our analytics api correct or not. Also we will have all analytics in one place.
  • Provide tiny api layer. Thus, the working time and object creation excess will be minimal. Also, we will be able to create analytics double-quick.
  • Provide OOP way to work with analytics. Thus, we will able to mock analytics in test classes, and write appropriate tests with not disturbing analytics system.

Actions with single label

interface CategoryInterface {
fun action(label: Label)
enum class Label { MY_LABEL_NAME }
}
interface CategoryInterface {
@LabelFun(“action”) fun myLabelName()
}
interface CategoryInterface {
fun show(label: PriceCategory)
@LabelFun(“show”, “all_prices”) showAll()
}

interface CategoryInterface {
@LabelFun(“show”, “low_prices”) fun showLow()
@LabelFun(“show”, “medium_prices”) fun showMedium()
@LabelFun(“show”, “high_prices”) fun showHigh()
@LabelFun(“show”, “all_prices”) fun showAll()
}

Postfixes

//example of using @HasPrefix without arguments
interface CategoryInterface {
@HasPrefix fun action()
}
//will produce action = "categoryinterfaceaction"
//example of using @HasPostfix without arguments
interface CategoryInterface {
@HasPostfix fun action()
}
will not compile, since @HasPostfix require to define a name of postfix
interface AnalyticsRange {
fun fromOd(value: Int)
fun toOd(value: Int)
}
@HasPostfix("Od")
interface AnalyticsRange {
fun from(value: Int)
fun to(value: Int)
}

Support of properties in Group Interfaces

interface GroupInterface {
fun category(): AnalyticsCategory
fun otherCategory(): AnalyticsOtherCategory
}
interface AnalyticsCategory {
fun action()
}
interface AnalyticsOtherCategory {
fun action()
}
//invocation part
groupInterface.category().action()
groupInterface.otherCategory().action()
interface GroupInterface {
val category: AnalyticsCategory
val otherCategory: AnalyticsOtherCategory
}
interface AnalyticsCategory {
fun action()
}
interface AnalyticsOtherCategory {
fun action()
}
//invocation part
groupInterface.category.action()
groupInterface.otherCategory.action()

Optimized memory consuming

interface Analytics {
val seller: AnalyticsSeller
val customer: AnalyticsCustomer
}
interface AnalyticsSeller {
fun sell(what: String)
}
interface AnalyticsCustomer {
fun buy(what: String)
}
analytics.seller.sell("something")
analytics.customer.buy("something")

That’s all?

Afterwords

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Spitsin

Michael Spitsin

Love being creative to solve some problems with an simple and elegant ways