Design with inheritance and two 1 to many relationships to the same table

Quick schema overview:
Below is a schema being a subject of my question. In the design there are two “regular” tables questions and notes as well as two “abstract” tables:

  • elements, with “concrete” implementations:
    • video_clips, podcasts, books, articles
  • markers with following “implementations”:
    • book_pages, article_pages and time_frames

What I would like to achieve:
I would like to be able to put a note or a question in an element. But along with the information that let me find it quicker, thus f.e. if book was my element, I would use a page marker (book_page). If podcast was my element I would use a minute marker (time_frame).

To give an example: Let’s say I have:

  • a book B1 with 100 pages
  • a book B2 with 200 pages
  • a podcast P1 that lasts 8 minutes

Now I want to be able to put a note for page number 21 for the book B1 saying: Unlike many other metals, iron does not form amalgams with mercury. – f.e. because that statement drew my attention while reading the book and I want to highlight that by putting a note with that sentence, and connect it to B1 p. 21.

Let’s say in podcast P1 in minute 4 I heard a sentence: Bank A has better mortgage plan than bank B because X Y Z. I want to be able to put a question related to P1 and minute 4 saying: Why X is better in bank A and not C?

There are two important topics related to that design:

  1. Inheritance
  2. Two 1 to many relationships to the same table

I could get rid of the markers table, and relate book_pages with books, article_pages with articles and time_frames with both podcasts and video_clips. The problem is that I would have two FK in time_frames (let’s assume it’s acceptable with CHECK constraint) and three foreign keys in both notes and questions (book_page_id,article_page_id,time_frame_id) – and that is unacceptable. I’ve introduced markers table to solve that issue and have only one FK in notes and questions. Unfortunately that comes with high price, because now querying for an element needs twice more joins (for elements and markers).

I am not looking for the perfect solution because giving the problems there isn’t one, I know I need to adopt the compromise but the question is if my compromise/design is acceptable or not ?

user created schema being a subject of the present question

Repaying care expenses for a parent from inheritance

This is a practical question, looking for existing Shu”Ts that cover this scenario:

  • A child takes care of his old and dying father for a couple of years – he feeds him, pays for a nurse, housekeeper etc.
  • The father does not talk and neither of them is explicitly mentioning his monetary intentions.
  • One day the father dies and inherits the house to his two sons.
  • The first son claims that his expenses must be repaid before splitting the inheritance money.

According to the Halacha that the expenses for honoring parents are on the parents themselves, Is he right?

How does Prototypical Inheritance works in JS

I am trying prototypical inheritance in order to calculate distance(). But I am getting an error which is TypeError: Cannot read property 'x' of undefined. The error line is marked at the code. I know that the way I am calculating distance() is wrong. But someone can guide me what is the correct way?

'use strict';

 function Shape(x,y){
    this.x = x;
    this.y = y;

  Shape.prototype.distance = function(s1,s2){
    // this.distance = function(s1,s2){
      const xDiff = this.s1.x - this.s2.x;         //error
      const yDiff = this.s1.y - this.s2.y;
      return Math.sqrt(xDiff*xDiff + yDiff*yDiff);      
    // }

 function Circle(x,y,radius){,x,y);
    this.radius = radius;
    this.area = Math.PI*this.radius*this.radius;

 function Rectangle(x,y,w,h){,x,y);
  this.width =w;
  this.height =h;
  this.area = this.width * this.height;  

Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.constructor = Circle;

Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;

const shapes = [
  new Rectangle(3,4,5,6),
  new Circle(0,0,1),

shapes.forEach((s) => console.log(s.x, s.y, s.area));

Classical inheritance vs prototypal inheritance in Javascript VS Objective-C VS Swift

I’m an iOS developer who learn Javascript now.
My previous experience is related to Objective-C and Swift.

However prototype inheritance in JS got be confused when I try to compare it with inheritance model in Objective-C and Swift.
I’ve read a lot of articles on this topic but still have some questions.
My questions are:

1) Does the answer on the inheritance type model significantly depend on the specific language at all?

2) In Javascript as I understand there is no such concept as Class and even ES6 Class acts as a wrapper for Prototype.
Prototype doesn’t work as a blueprint as in classical inheritance model.

Where is the border between Class and Prototype in the context of blue-print?

3) A lot of articles I’ve read highlighted Javascript flexibility to change prototypes chains on the fly.

However in Objective-C using objc runtime we can slightly achieve something like replacing superclass by isa swizzling. Or add methods/properties “on the fly” with objc.runtime.
And Class serves as an object itself in Objective-C. It has an isa pointer to superclass, can respond to messages, etc.

Can we state that Objective-C (or other languages) can mimic prototype inheritance with some techniques?

Or in the context of this question Class should be treaded as an abstract term, rather than its implementation details?

4 Can we achieve smth like prototype inheritance in Swift?
Does it matter in the context of static/dynamic typed languages?

Use GKEntity’s component(ofType:) with inheritance

I’m writing a SpriteKit game in swift and making use of GameplayKit’s entity-component system. There are many components that do different stuff but share the same methods in which they do it, so I thought I’d group them into categories. At first I thought about using protocols, but component(ofType:) only accepts classes. So then I thought about making a base class for each category, define methods and variables there and have the actual components classes override them to implement their own functionality (you know like basic OOP). So I had something like:

class InputComponent: GKComponent {
    func handleInput() {

class ControllerComponent: InputComponent {
    override func handleInput() {
        //Do something

class KeyboardComponent: InputComponent {
    override func handleInput() {
        //Do something different

Then somewhere in my code I’d call

entity.component(ofType: InputComponent)

and I thought I’d get both ControllerComponent and KeyboardComponent type objects. But I am getting none, it seems component(ofType:) doesn’t return instances of subclasses.

I guess I can make an extension to GKEntity and define something like


(conformingTo protocol: P.Type)

and implement that behavior myself but I want to know if I can use the built in function to achieve the same.

Postgres table partitioning – declarative vs inheritance [on hold]

I have a table with over 70MM rows running on Postgres 9.6.6.
The table size is about 50GB (70GB with indexes). The table size is projected to triple in the next 3 months. The growth will slow after that.

The table has several varchar fields and 60+ numeric fields. Each row includes customer ID and every query uses customer ID. There are no JOINs – each query retrieves either a collection of rows, or aggregation over some collection of rows.

Any recommendations if I should

  1. keep 9.6.6 and using inheritance,
  2. upgrade to 10.4 and using declarative partitioning,
  3. try something else?

There are about 2,000 customer IDs at the moment. My plan is to have about 500 customers per partition.

Customer ID is a uniformly sparse int. Let’s say a random number between 1 and 1,000,000. I would use 100K ranges to partition it into 10 partitions.

Inheritance laws and dina d’malchuta dina

If someone dies and halacha says you get to inherit, but civil law says I do, who does? If we both agree to let a bet din decide the matter, then you inherit and the matter is closed. But if I take you to secular court and the court (after all appeals are exhausted) says I inherit, we have a clear question for dina d’malchuta dina. Does the latter ALWAYS apply in financial matters?

Aggregate inheritance in DDD [duplicate]

This question already has an answer here:

  • In DDD, how do I persist an aggregate containing polymorphism

    4 answers

So one thing you do not hear much about is inheritance with DDD. Currently I have an Account aggregate that handles details regarding a financial account and its subaccounts. Then a Transaction aggregate is used that maintains the invariants related to a financial transaction. The transaction is not a split transaction (yet), but links a credited account and debited account (via entity IDs).

When I compute the balance of an account, I use a domain service that takes in an AccountId and uses the AccountRepository and TransactionRepository to compute the balance.

So far so good, until I get to the idea of tracking investment accounts. This changes how the balance is computed. I need to use the last known share price with the amount of shares purchased to compute the balance.

So with different behavior, it makes sense to have an InvestmentAccount class that inherits from Account. However, I’m stuck on how to handle this with regards to using inheritance/polymorphism.

I do not want to have switch statements littered through my code so I thought polymorphism would be the answer. However, re-instantiating a supertype isn’t as easy as I suspected.

Am I missing a separate aggregate here? I had the idea of using the Strategy pattern to inject a different algorithm for computing the balance. But behavior isn’t the only different. I still need a way to track shares vs dollar amounts so that only gets me half of the way. This makes me think I need another class InvestmentAccount.