Which is a type of objects in mainstream OO languages: a class, an interface, an abstract class, a metaclass?

In Types and Programming Languages by Pierce, Section 18.6 Simple Classes in Chapter 18 Imperative Objects says:

We should emphasize that these classes are values, not types. Also we can, if we like, create many classes that generate objects of exactly the same type. In mainstream object-oriented languages like C++ and Java, classes have a more complex status—they are used both as compile-time types and as run-time data structures. This point is discussed further in §19.3.

The only place which Section 19.3 Nominal and Structural Type Systems says about classes is:

These type names play a crucial role in Java’s subtype relation. Whenever a new name is introduced (in a class or interface definition), the programmer explicitly declares which classes and interfaces the new one extends (or, in the case of a new class and an existing interface, “implements”). The compiler checks these declarations to make sure that the facilities provided by the new class or interface really extend those of each super-class or super-interface— this check corresponds to record subtyping in a typed lambda-calculus. The subtype relation is now defined between type names as the reflexive and tran- sitive closure of the declared immediate-subtype relation. If one name has not been declared to be a subtype of another, then it is not.

Does the above quote or some other places in Section 19.3 explain the second highlighted sentence in the first quote from Section 18.6, i.e. why

In mainstream object-oriented languages like C++ and Java, classes have a more complex status—they are used both as compile-time types and as run-time data structures

? (I don’t see Section 19.3 mentions that a class is a type of objects in mainstream OO languages, and even explains it.)

In Chapter 18 Imperative Objects, is an interface a type of objects?

In mainstream OO languages (such as Java, C#, I am not sure if C++ has interface),

  • is an interface a type of objects?

    An interface seems to me a type of classes, since many classes can implement the same interface. Since a class is a type of objects, is an interface a kind?

  • Is an abstract class essentially the same concept as an interface? (In terms of being a type of classes or something else)

I have a related post a while ago: Is the implementation relation between an interface and a class an instantiation or inheritance relation, or neither?. It also introduces concept “metaclass” of Python, and my confusions between interface, class, abstract class, and metaclass. Appreciate if you could also take that into account.

Thanks.

How to Steer a Moving Object Away From Another Object(s)

I’m working with C# in Unity, and I’m making a top-down space shooter game in which there are many different AI-controlled ships flying around. The problem is that these ships often fly on top of one another in passing, and sometimes even will fly the same route on top of one another if given the same waypoint. I want to add a system to steer my AI ships away from each other as well as other obstacles so that instead of overlapping one another when flying the same path they will fly side-by-side, and will also try to avoid things that pass in front of them.

My current system essentially works like this: The AI looks at all of the current objectives, points of interests, etc, and decides where it wants to be on the map (a coordinate). The AI then sends an input direction to the ship, which then applies acceleration in that direction and changes the velocity. Therefore, any solution to alter my ship’s pathing would need to alter this input direction somehow.

So my first idea was to check if there are any obstacles (ships, asteroids, structures, etc) within a radius of the ship, increasing this radius based on the ship’s velocity (higher velocity = larger “view” radius):

Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, ship.velocity.magnitude); 

If there is something nearby, calculate the direction to that collision, then calculate the opposite direction and scale it to the reciprocal, which also has the added effect of making the aversion stronger the shorter the distance to the collision is:

foreach (Collider2D hit in hits) {    Vector2 v = hit.ClosestPoint(transform.position) - (Vector2)transform.position;    v = (1 / v.magnitude) * -v.normalized; 

I would perform this for every nearby obstacle and add all of these together to get the avoidance vector:

   avoidanceVector += v;    continue; } 

Then I add the total avoidance vector to the AI’s input direction and normalize the result:

inputDirection += avoidanceVector; inputDirection.Normalize(); 

However, when i add this avoidance vector to my input direction, my ships exhibit a strange behavior where sometimes they will simply stop moving completely. commenting out the line where i add them together stops this behavior.

I’m really not sure what could be going wrong here, but I think it has to do with my approach altogether. Can anyone help me figure out a clean, simple way to make my ships steer away from other objects?

What is the difference between ADT and existential objects?

Section 24.2 in Types and Programming Languages by Pierce introduces ADTs and implements them in existential types:

A conventional abstract data type (or ADT) consists of (1) a type name A, (2) a concrete representation type T, (3) implementations of some operations for creating, querying, and manipulating values of type T, and (4) an abstraction boundary enclosing the representation and operations. Inside this boundary, elements of the type are viewed concretely (with type T). Outside, they are viewed abstractly, with type A. Values of type A may be passed around, stored in data structures, etc., but not directly examined or changed—the only operations allowed on A are those provided by the ADT. … We first create an existential package containing the internals of the ADT:

counterADT = {*Nat, {new = 1, get = λi:Nat. i, inc = λi:Nat. succ(i)}} as {∃Counter, {new: Counter, get: Counter→Nat, inc: Counter→Counter}};  > counterADT : {∃Counter, {new:Counter,get:Counter→Nat,inc:Counter→Counter}} 

We can open it for example

let {Counter,counter} = counterADT in counter.get (counter.inc counter.new); > 2 : Nat 

and then introduces existential objects and implement them in existential types:

A counter object comprises two basic components: a number (its internal state), and a pair of methods, get and inc, that can be used to manipulate the state. We also need to ensure that the only way that the state can be queried or updated is by using one of these two methods. This can be accomplished by wrapping the state and methods in an existential package, abstracting the type of the state. For example, a counter object holding the value 5 might be written

c = {*Nat, {state = 5, methods = {get = λx:Nat. x, inc = λx:Nat. succ(x)}}} as Counter; 

where:

Counter = {∃X, {state:X, methods: {get:X→Nat, inc:X→X}}}; 

We opens it for example:

let {X,body} = c in body.methods.get(body.state); > 5 : Nat 

and finally compare ADTs and existential objects:

when programming with ADTs, packages are opened immediately after they are built; on the other hand, when packages are used to model objects they are kept closed as long as possible—until the moment when they must be opened so that one of the methods can be applied to the internal state.

  • What are the fundamental differences in the implementations of ADT and of existential objects, in terms of existential types? (They are visually different, but I can’t figure out what the visual differences imply.)

  • Why “when programming with ADTs, packages are opened immediately after they are built; on the other hand, when packages are used to model objects they are kept closed as long as possible“?

Thanks.

Amazing video tracking with places and objects for $15

I am a professional video editor. I will track your picture or message on objects and places. I will make videos for your vlogs or promotional videos with eye catching visual effects for your business.Check out video sample:https://drive.google.com/file/d/1cUPugJcsyMw42XX4w5dEb8VHbOA8m49B/view?usp=sharing

by: ContentCreator
Created: —
Category: Video
Viewed: 198


Properly passing objects between my applications models/modules

I have several models/modules such as User, Wallet, both these modules that are called from the express application such as User.login(req,res);

right now in each User.js and Wallet.js I am including database.js which looks like this:

 var mysql = require('mysql2/promise') var pool = mysql.createPool({     connectionLimit: 10,     host: 'localhost',     user: 'x',     password: 'x',     database: 'x' }); pool.getConnection((err, connection) => {     if (err) {         if (err.code...
Code (markup):

Properly passing objects between my applications models/modules

How to pass objects between functions in PnP PowerShell

I have to functions. In the first, I create a reference to a SharePoint list. I would like to pass the list to a second function. In the second functions list of parameters, I declare it as String

This doesn’t work. How do I declare the parameter as being a list?

function GetList() {     param(     [string] $  listID,     [string] $  listName     )     Write-Host "Provided ListName: " $  listName -ForegroundColor Cyan     Write-Host "The list id is: " $  listID -ForegroundColor Red      $  list = Get-PnPList -Identity $  listName       CreateView -list $  list  }  function CreateView()  {     param(     [string] $  list     )      Add-PnpView -Title "Test View" -List $  list -Fields "Title"     Write-Host "Creating New View" } 

How to compare objects which are having multiple comparable field-values?

class File {   // Descriptive fields   string name;   string id;   string uploader_id;    // ----Comparable fields----   uint   downloads;  // 40% importance   uint   size_in_bytes;  // 20% importance   time_t time_millisec_created;  // 20% importance   time_t time_millisec_last_used;  // 20% importance }; 

In an array of such File objects, I want to find out an element from an array, which is delete-able. This element can be decided based on the “Comparable fields” mentioned above. Lower the value, it’s more delete-able.

Now, I can’t make a simple comparator operator due to complexity involved of percentage value.

What is a reasonable & rational way of comparing 2 such File objects?