# superclass

In object-oriented design, a superclass is a generic class from which more specific subclasses are derived.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## EveryThing You Need To Know About Scala

DevFeed: [EveryThing You Need To Know About Scala](<https://devfeed.tech/articles/everything-you-need-to-know-about-scala-65415.md>)

Original publisher: [Read original article](<https://blog.devops.dev/everything-you-need-to-know-about-scala-c833fe885c44?source=rss----33f8b2d9a328---4>)

Author: Rahul Patidar

Published: 2026-10-06T13:04:28Z

Content type: article

Language: en

Sources: [DevOps.dev](<https://devfeed.tech/sources/devops-dev.md>)

Topics: [Scala](<https://devfeed.tech/topics/scala.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [class](<https://devfeed.tech/topics/class.md>), [Closure](<https://devfeed.tech/topics/closure.md>), [constructor](<https://devfeed.tech/topics/constructor.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Learning](<https://devfeed.tech/topics/learning.md>), [superclass](<https://devfeed.tech/topics/superclass.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [block](<https://devfeed.tech/tags/block.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [closure](<https://devfeed.tech/tags/closure.md>), [design-patterns](<https://devfeed.tech/tags/design-patterns.md>), [exception](<https://devfeed.tech/tags/exception.md>), [exception-handling](<https://devfeed.tech/tags/exception-handling.md>), [factory](<https://devfeed.tech/tags/factory.md>), [frameworks](<https://devfeed.tech/tags/frameworks.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [monad](<https://devfeed.tech/tags/monad.md>), [none](<https://devfeed.tech/tags/none.md>), [nothing](<https://devfeed.tech/tags/nothing.md>), [null](<https://devfeed.tech/tags/null.md>), [packages](<https://devfeed.tech/tags/packages.md>), [recursion](<https://devfeed.tech/tags/recursion.md>), [scala](<https://devfeed.tech/tags/scala.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

The excerpt presents Scala interview topics through short explanations and code examples. It describes factory, singleton, and lazy initialization patterns; treating functions as values and higher-order functions; tail recursion, closures, placeholder syntax, partially applied functions, currying, purity, and anonymous functions. It also covers trait linearization in the diamond problem, monads, case class features, primary and auxiliary constructors, named Scala frameworks, exception handling without checked exceptions, BitSet, the App helper, package names, and Null, Nil, None, and Nothing. The supplied text ends mid-example in the factory pattern and is therefore an excerpt rather than evidence of the complete article.

### Source excerpt

Everyone who is a beginner in scala faces many problems and has many confusions while trying to understand important concepts in scala. In interviews, interviewers frequently ask about these concepts in Scala, and candidates are frequently unable to impress or explain these concepts to interviewers. So in today's post, I will be covering some important concepts in Scala, so whenever you go for your next interview, just read these concepts once and it will really help you to answer Scala Related Interview Questions. This post will cover the following topics: 1. Scala Design Patterns 2. First Class function 3. Higher-Order Functions 4. Tail Recursion in Scala. 5. Block of Code. 6. Closure 7. PlaceHolder Syntax: 8. Partially Applied Function: 9. Function Currying : 10. pure functions : 11. Anonymous Function: 12. Diamond Problem In scala: 13. traint in scala: 14. Monad in scala: 15. Case Classes In Scala. 16. constructors in Scala 17. Frameworks supported by Scala 18. Exception Handling in Scala 19. BitSet 20. app Class 21. Packages in Scala 22. Null, Nill, None, and Nothing in Scala Scala Design Patterns. Every time you develop some software, there are some common problems that everyone faces in his/her software engineering journey. To resolve these issues, we have some predefined general-purpose reusable solutions. These reusable solutions are nothing but design patterns. These are the types of templates that we can use as a solution whenever we encounter these issues. We have 3 kinds of design patterns in Scala. The factory design pattern: the main aim of the factory design pattern is to separate instance creation logic from the client. Here we implement instance creation logic in the factory class without exposing this logic to the client. It is used when we have multiple subclasses with one superclass and, based on the input, we need to return one of the inputs. Example trait Computer { def ram: String def hdd: String def cpu: String } case class PC(ram: String, h

## Benchmarks Are Free Now

DevFeed: [Benchmarks Are Free Now](<https://devfeed.tech/articles/benchmarks-are-free-now-20533.md>)

Original publisher: [Read original article](<https://code.dblock.org/2026/08/15/benchmarks-are-free-now.html>)

Author: Daniel Doubrovkine (dblock@dblock.org)

Published: 2026-08-15T00:00:00Z

Content type: opinion

Language: en

Sources: [Daniel Doubrovkine](<https://devfeed.tech/sources/daniel-doubrovkine.md>)

Topics: [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [subclass](<https://devfeed.tech/topics/subclass.md>), [superclass](<https://devfeed.tech/topics/superclass.md>), [Tool](<https://devfeed.tech/topics/tool.md>), [GitHub Copilot Profiler Agent](<https://devfeed.tech/topics/github-copilot-profiler-agent.md>)

Tags: [agent](<https://devfeed.tech/tags/agent.md>), [ai](<https://devfeed.tech/tags/ai.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [caching](<https://devfeed.tech/tags/caching.md>), [class](<https://devfeed.tech/tags/class.md>), [copilot](<https://devfeed.tech/tags/copilot.md>), [cost](<https://devfeed.tech/tags/cost.md>), [dispatch](<https://devfeed.tech/tags/dispatch.md>), [exhaustive](<https://devfeed.tech/tags/exhaustive.md>), [fast](<https://devfeed.tech/tags/fast.md>), [free](<https://devfeed.tech/tags/free.md>), [hash](<https://devfeed.tech/tags/hash.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [performance](<https://devfeed.tech/tags/performance.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [script](<https://devfeed.tech/tags/script.md>), [speed](<https://devfeed.tech/tags/speed.md>), [subclass](<https://devfeed.tech/tags/subclass.md>), [test](<https://devfeed.tech/tags/test.md>), [tests](<https://devfeed.tech/tags/tests.md>), [time](<https://devfeed.tech/tags/time.md>)

### AI overview

A benchmark generated with Copilot CLI exposed a performance regression in ruby-enum's inheritance fix: subclass lookups repeatedly rebuilt merged enum hashes, making a one-level subclass's calls roughly 5x slower than base-class calls, with deeper inheritance slower still. Tests had caught no issue because they checked correctness, not speed. The author says fix #60 memoized the merged hash and invalidated the cache when a new entry was added; afterward, subclass lookups were indistinguishable from base-class lookups regardless of depth. Further benchmarks found constant access as fast as plain Ruby, hash-backed lookups about 3-5x slower than direct calls, and the exhaustive matcher 50-100x slower than a native statement. The excerpt says these measurements were added to the README's Performance section.

### Source excerpt

My previous post walked through four bugs in ruby-enum, a gem I maintain, all stemming from the fact that class-level instance variables aren't inherited by subclasses. The third fix, #59, made keys, key?, value?, key, value, to_h, parse and each walk up superclass and merge in a parent's enums, so a subclass would see everything its ancestors defined. It was correct, fully tested, and shipped. It also made every one of those methods roughly 5x slower on any subclass. def _enum_hash if superclass < Ruby::Enum superclass.send(:_enum_hash).merge(_own_enum_hash) else _own_enum_hash end end This recomputes the merged hash, walking the entire ancestor chain, on every single call. There's no caching. A one-level subclass calling .value pays for building a brand new hash, on top of the superclass doing the same, every time. The test suite didn't notice because tests check correctness, not speed, and correctness was fine. I only found this because I asked Copilot CLI to add a benchmark script comparing lookups at different inheritance depths, mostly out of curiosity about how the "Benchmarks" section of the README would read next to the new feature. It took one prompt and about a minute to get a working script: class Colors include Ruby::Enum define :RED, 'red' define :GREEN, 'green' end class SubColors < Colors define :BLUE, 'blue' end class SubSubColors < SubColors define :YELLOW, 'yellow' end benchmark('base class (no inheritance)', n) { Colors.value(:RED) } benchmark('subclass (1 level)', n) { SubColors.value(:RED) } benchmark('sub-subclass (2 levels)', n) { SubSubColors.value(:RED) } The first run told the story immediately: a 1-level subclass's .value calls took roughly 5x as long as the base class, and a 2-level subclass was worse still. Nobody had written this benchmark before merging #59 because writing a throwaway benchmark script used to feel like more ceremony than it was worth for a one-off performance check. Now it's a single sentence to an agent, and the scri

## The Liskov Substitution Principle does more than you think

DevFeed: [The Liskov Substitution Principle does more than you think](<https://devfeed.tech/articles/the-liskov-substitution-principle-does-more-than-you-think-25507.md>)

Original publisher: [Read original article](<https://buttondown.com/hillelwayne/archive/the-liskov-substitution-principle-does-more-than/>)

Author: Hillel Wayne

Published: 2026-01-06T16:51:26Z

Content type: article

Language: en

Sources: [Newsletter feed for Hillel Wayne's Newsletter](<https://devfeed.tech/sources/newsletter-feed-for-hillel-wayne-s-newsletter.md>)

Topics: [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>), [superclass](<https://devfeed.tech/topics/superclass.md>)

Tags: [call](<https://devfeed.tech/tags/call.md>), [code](<https://devfeed.tech/tags/code.md>), [example](<https://devfeed.tech/tags/example.md>), [execution](<https://devfeed.tech/tags/execution.md>), [f](<https://devfeed.tech/tags/f.md>), [history](<https://devfeed.tech/tags/history.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [invariants](<https://devfeed.tech/tags/invariants.md>), [logic-for-programmers](<https://devfeed.tech/tags/logic-for-programmers.md>), [lsp](<https://devfeed.tech/tags/lsp.md>), [oop](<https://devfeed.tech/tags/oop.md>), [operator](<https://devfeed.tech/tags/operator.md>), [paper](<https://devfeed.tech/tags/paper.md>), [root](<https://devfeed.tech/tags/root.md>), [solid](<https://devfeed.tech/tags/solid.md>), [solid-principles](<https://devfeed.tech/tags/solid-principles.md>), [square](<https://devfeed.tech/tags/square.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [tests](<https://devfeed.tech/tags/tests.md>), [wing](<https://devfeed.tech/tags/wing.md>)

### AI overview

The excerpt presents Liskov substitution as a behavioral guarantee beyond merely using inheritance: any property that holds for a supertype should also hold for its subtype. It gives three conditions for correct subtyping: subtype methods must have equal or weaker preconditions and equal or stronger postconditions; the subtype must preserve the supertype's state invariants; and it must preserve its history properties, such as keeping an immutable field immutable. The author focuses on method contracts and says the first condition can be formally deduced, but the excerpt ends before showing that derivation.

### Source excerpt

Happy New Year! I'm done with the newsletter hiatus and am going to try updating weekly again. To ease into things a bit, I'll try to keep posts a little more off the cuff and casual for a while, at least until Logic for Programmers is done. Speaking of which, v0.13 should be out by the end of this month. So for this newsletter I want to talk about the Liskov Substitution Principle (LSP). Last week I read A SOLID Load of Bull by cryptographer Loupe Vaillant, where he argues the SOLID principles of OOP are not worth following. He makes an exception for LSP, but also claims that it's "just subtyping" and further: If I were trying really hard to be negative about the Liskov substitution principle, I would stress that it only applies when inheritance is involved, and inheritance is strongly discouraged anyway. LSP is more interesting than that! In the original paper, A Behavioral Notion of Subtyping, Barbara Liskov and Jeannette Wing start by defining a "correct" subtyping as follows: Subtype Requirement: Let ϕ(x) be a property provable about objects x of type T. Then ϕ(y) should be true for objects y of type S where S is a subtype of T. From then on, the paper determine what guarantees that a subtype is correct.1 They identify three conditions: Each of the subtype's methods has the same or weaker preconditions and the same or stronger postconditions as the corresponding supertype method.2 The subtype satisfies all state invariants of the supertype. The subtype satisfies all "history properties" of the supertype. 3 e.g. if a supertype has an immutable field, the subtype cannot make it mutable. (Later, Elisa Baniassad and Alexander Summers would realize these are equivalent to "the subtype passes all black-box tests designed for the supertype", which I wrote a little bit more about here.) I want to focus on the first rule about preconditions and postconditions. This refers to the method's contract. For a function f, f.Pre is what must be true going into the function, and

## Class Pollution in Ruby: A Deep Dive into Exploiting Recursive Merges

DevFeed: [Class Pollution in Ruby: A Deep Dive into Exploiting Recursive Merges](<https://devfeed.tech/articles/class-pollution-in-ruby-a-deep-dive-into-exploiting-recursive-merges-92053.md>)

Original publisher: [Read original article](<https://blog.doyensec.com/2024/10/02/class-pollution-ruby.html>)

Published: 2024-10-01T22:00:00Z

Content type: article

Language: en

Sources: [Doyensec](<https://devfeed.tech/sources/doyensec.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [class](<https://devfeed.tech/topics/class.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [superclass](<https://devfeed.tech/topics/superclass.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

Tags: [about](<https://devfeed.tech/tags/about.md>), [admin](<https://devfeed.tech/tags/admin.md>), [allows](<https://devfeed.tech/tags/allows.md>), [alter](<https://devfeed.tech/tags/alter.md>), [application](<https://devfeed.tech/tags/application.md>), [auditing](<https://devfeed.tech/tags/auditing.md>), [automation](<https://devfeed.tech/tags/automation.md>), [base](<https://devfeed.tech/tags/base.md>), [based](<https://devfeed.tech/tags/based.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [behaviors](<https://devfeed.tech/tags/behaviors.md>), [blog](<https://devfeed.tech/tags/blog.md>), [blog-post](<https://devfeed.tech/tags/blog-post.md>), [can](<https://devfeed.tech/tags/can.md>), [cases](<https://devfeed.tech/tags/cases.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [deep](<https://devfeed.tech/tags/deep.md>), [deep-dive](<https://devfeed.tech/tags/deep-dive.md>), [dive](<https://devfeed.tech/tags/dive.md>), [doyensec](<https://devfeed.tech/tags/doyensec.md>), [doyensecurity](<https://devfeed.tech/tags/doyensecurity.md>), [exploit](<https://devfeed.tech/tags/exploit.md>), [hacking](<https://devfeed.tech/tags/hacking.md>), [infosec](<https://devfeed.tech/tags/infosec.md>), [offensive](<https://devfeed.tech/tags/offensive.md>), [pentest](<https://devfeed.tech/tags/pentest.md>), [pentester](<https://devfeed.tech/tags/pentester.md>), [pollution](<https://devfeed.tech/tags/pollution.md>), [reverse-engineering](<https://devfeed.tech/tags/reverse-engineering.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [security](<https://devfeed.tech/tags/security.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>)

### AI overview

Recursive merges that assign data to Ruby object attributes can alter behavior beyond the supplied values, and recursive traversal can escape an object to affect parent or unrelated classes. The article distinguishes hash-only merges, which it says cannot pollute classes, from nonrecursive attribute merges, which affect one object, and recursive attribute merges, which can have broader effects. Its example shows instance-level method injection enabling privilege escalation or code execution when protected methods are evaluated. ActiveSupport's `deep_merge` works on hashes and becomes risky in the article's example when merged values are then assigned as object attributes. Hashie merges object attributes and blocks direct method replacement, but the article describes an exception involving the `_` attribute that can bypass an authorization check. Further examples demonstrate poisoning a parent class variable to redirect HTTP requests and repeatedly targeting subclasses to alter a signing key; the latter is random and may over-infect classes. The article concludes that recursive merges of untrusted data can compromise application behavior across requests.

### Source excerpt

Introduction In this post, we are going to explore a rarely discussed class of vulnerabilities in Ruby, known as class pollution. This concept is inspired by the idea of prototype pollution in JavaScript, where recursive merges are exploited to poison the prototype of objects, leading to unexpected behaviors. This idea was initially discussed in a blog post about prototype pollution in Python, in which the researcher used recursive merging to poison class variables and eventually global variables via the __globals__ attribute. In Ruby, we can categorize class pollution into three main cases: Merge on Hashes: In this scenario, class pollution isn't possible because the merge operation is confined to the hash itself. Merge on Attributes (Non-Recursive): Here, we can poison the instance variables of an object, potentially replacing methods by injecting return values. This pollution is limited to the object itself and does not affect the class. current_obj.instance_variable_set("@#{key}", new_object) current_obj.singleton_class.attr_accessor key Merge on Attributes (Recursive): In this case, the recursive nature of the merge allows us to escape the object context and poison attributes or methods of parent classes or even unrelated classes, leading to a broader impact on the application. Merge on Attributes Let's start by examining a code example where we exploit a recursive merge to modify object methods and alter the application's behavior. This type of pollution is limited to the object itself. require 'json' # Base class for both Admin and Regular users class Person attr_accessor :name, :age, :details def initialize(name:, age:, details:) @name = name @age = age @details = details end # Method to merge additional data into the object def merge_with(additional) recursive_merge(self, additional) end # Authorize based on the `to_s` method result def authorize if to_s == "Admin" puts "Access granted: #{@name} is an admin." else puts "Access denied: #{@name} is not an adm

## How to create a parameterized base test class in Kotlin

DevFeed: [How to create a parameterized base test class in Kotlin](<https://devfeed.tech/articles/how-to-create-a-parameterized-base-test-class-in-kotlin-25575.md>)

Original publisher: [Read original article](<https://www.marcogomiero.com/posts/2023/parameterized-kotlin-base-test/>)

Author: Marco Gomiero

Published: 2023-01-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Posts on Marco Gomiero](<https://devfeed.tech/sources/posts-on-marco-gomiero.md>)

Topics: [table driven tests](<https://devfeed.tech/topics/table-driven-tests.md>), [test data](<https://devfeed.tech/topics/test-data.md>), [class](<https://devfeed.tech/topics/class.md>), [superclass](<https://devfeed.tech/topics/superclass.md>)

Tags: [arguments](<https://devfeed.tech/tags/arguments.md>), [base](<https://devfeed.tech/tags/base.md>), [companion](<https://devfeed.tech/tags/companion.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [environment](<https://devfeed.tech/tags/environment.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [junit](<https://devfeed.tech/tags/junit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [runner](<https://devfeed.tech/tags/runner.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

JUnit 4's Parameterized runner injects test arguments through the test class constructor, with the argument set defined in that class's companion object. For tests that need shared setup, the text describes making a base test class accept an argument and define the required arguments in its companion object; concrete test classes then extend the base class, use the runner, and pass the argument to the base-class constructor. This enables the same tests to run across multiple inputs with shared configuration. The excerpt focuses on JUnit 4, though it notes JUnit 5 also offers parameterized tests.

### Source excerpt

One exciting feature of JUnit 4 (and 5 as well, but this post will be focused on JUnit 4) is the possibility of running the same test with different input arguments. That is made possible by a custom test runner called Parameterized, which will inject the provided arguments in the constructor of the test class. Instead, the different arguments must be defined in the companion object of the test class.

## Introduction to Interfaces

DevFeed: [Introduction to Interfaces](<https://devfeed.tech/articles/introduction-to-interfaces-25058.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-interfaces/>)

Author: author@typealias.com (Dave Leeds)

Published: 2022-09-12T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [interface](<https://devfeed.tech/topics/interface.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>), [superclass](<https://devfeed.tech/topics/superclass.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>)

Tags: [abstraction](<https://devfeed.tech/tags/abstraction.md>), [cast](<https://devfeed.tech/tags/cast.md>), [classes](<https://devfeed.tech/tags/classes.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [safe-cast](<https://devfeed.tech/tags/safe-cast.md>), [smart-cast](<https://devfeed.tech/tags/smart-cast.md>), [unsafe-cast](<https://devfeed.tech/tags/unsafe-cast.md>)

### AI overview

The excerpt introduces Kotlin interfaces as a way for one object to have more than one type. It begins illustrating the topic with a farm scenario: Farmer Sue greets her chicken Henrietta, who clucks back; the excerpt ends before showing the Kotlin implementation.

### Source excerpt

Ever since Chapter 1, we've used a variety of built-in Kotlin types, like Int, String, and Boolean. Then in Chapter 4, we introduced our own custom types, like Circle, by writing classes. In this chapter, we'll dive into interfaces, which allow you to declare that a single object has more than one type at a time! Interfaces are a powerful language feature, and when used well, they can take your code to the next level.

## Under the hood of Kotlin Class Delegation

DevFeed: [Under the hood of Kotlin Class Delegation](<https://devfeed.tech/articles/under-the-hood-of-kotlin-class-delegation-25974.md>)

Original publisher: [Read original article](<https://medium.com/snapp-mobile/under-the-hood-of-kotlin-class-delegation-24d53f9aa924?source=rss-8efc0359e234------2>)

Author: Jossi Wolf

Published: 2019-04-09T13:20:12Z

Content type: article

Language: en

Sources: [Jossi Wolf](<https://devfeed.tech/sources/stories-by-jossi-wolf-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [class](<https://devfeed.tech/topics/class.md>), [superclass](<https://devfeed.tech/topics/superclass.md>), [interface implementation](<https://devfeed.tech/topics/interface-implementation.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>), [adapter pattern](<https://devfeed.tech/topics/adapter-pattern.md>), [Image](<https://devfeed.tech/topics/image.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [class](<https://devfeed.tech/tags/class.md>), [composition-over-inheritance](<https://devfeed.tech/tags/composition-over-inheritance.md>), [delegation](<https://devfeed.tech/tags/delegation.md>), [hood](<https://devfeed.tech/tags/hood.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [logic](<https://devfeed.tech/tags/logic.md>), [stories](<https://devfeed.tech/tags/stories.md>)

### AI overview

Kotlin class delegation can expose an API through a class without filling that class with proxy calls. In the example, a custom view delegates an interface's methods to a separate implementation using Kotlin's `by` keyword, keeping the logic extracted and the view less cluttered. The excerpt explains that Kotlin generates functions that invoke the delegate; with many methods, this generated code adds to compiled size even as it reduces clutter in the source.

### Source excerpt

I was told to add an image to the post, so here's one Photo by Jf Brou from Unsplash. Bonus points since Samoyeds are some of the cutest dogs out there! A piece of rather popular advice heard in software development is "favour composition over inheritance". I won't go into the details of why as there is an excellent chapter in "Effective Java" about it, as well as this nice article by Eric Lin. This article explores how class delegation can be useful and how it works under the hood. In our case, we had a custom view which should expose an interface looking like this: https://medium.com/media/2efb0d0125ffec7f388ee2df190bcf6a/href Now it was time to create the CanvasCapabilities implementation. https://medium.com/media/3d8b72ac99b28b99f39c95c882a69dce/href Of course, we don't want to start putting logic into our view just for the sake of exposing the interface through it, which meant that the view now had to act as a "proxy" (implementing the interface and calling the ArtboardCanvas ): https://medium.com/media/f3d51d082e7f23d725ef7efafb3fe131/href Not a nice solution, but at least we extracted the logic. The view was still cluttered though :( Class Delegation to the rescue Using the by keyword in Kotlin, properties and even classes can be delegated. You might know it from using lazy : https://medium.com/media/cbea2e6d1363f31e28552d9a8c87823e/href You can also delegate inheritance, which is what we are after. The usage looks like this: https://medium.com/media/5482d423d1b2a0fcff239f25c4ab31e9/href This delegates the methods from CanvasCapabilities to ArtboardCanvas . No more cluttering with "proxy" calls! Under The Hood Under the hood, Kotlin actually doesn't do any "black magic": It just generates a function which invokes the delegate. The bytecode, decompiled to Java looks like this: https://medium.com/media/34cf5d85a4bcf122bc98d74425e9a5dd/href If you have a lot of methods, that code will still be generated and adding to your compiled code's size, but at least it do

## Covariance

DevFeed: [Covariance](<https://devfeed.tech/articles/covariance-25011.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/covariance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-11-14T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [data type](<https://devfeed.tech/topics/data-type.md>), [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [subclass](<https://devfeed.tech/topics/subclass.md>), [superclass](<https://devfeed.tech/topics/superclass.md>), [class](<https://devfeed.tech/topics/class.md>)

Tags: [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

Covariance means two type relationships subtype in the same direction. In Kotlin, a read-only List is covariant: if B is a subtype of A, List<B> can be used where List<A> is expected. MutableList is not covariant, since allowing that substitution could make writes unsafe. Generic classes are invariant by default; marking a parameter `out` permits covariance but requires the class to only produce that type, not accept it as a function argument or setter value. The excerpt also notes that subclass overrides may use a more specific return type, though its example is cut off.

### Source excerpt

On the surface, subtypes seem straightforward. Most programmers who write object-oriented code are familiar with the concept of inheritance, and how you can pass off a subclass as if it were its superclass. But subtyping rules aren't always as intuitive when you start working with generics. What is Covariance? Covariance describes a relationship between two sets of types where they both subtype in the same direction. For example, for our first set of types, here are two classes, A and B, where B is a subtype of A: