difference between inherit Directive and INHERIT Configuration Directive in bitbake - yocto

I am new to bitbake and i am learing it.
Can you please help me understand the difference between inherit Directive and INHERIT Configuration Directive?
My understanding on inherit Directive:
inherit Directive is used to inherit a class from .bbclass file into another .bbclass file or .bb(recipe) file
I am not able to understand what is INHERIT Configuration Directive?i saw the syntax INHERIT += "abc".what is it trying to do?why do we have 2 different inherit directives?
Thanks in advance

The difference between inherit and INHERIT is simple and is well explained in the Yocto documentation here:
... using INHERIT to inherit a class effectively inherits the class
globally
So, there are two differences between them:
Inheritance scope:
inherit only inherits a class for a given recipe
INHERIT inherits the class globally for all recipes, so all recipes have access to the classes functions or tasks, meaning if you have main tasks in that class (do_install, do_compile, ...) it will affect all recipes.
Execution:
inherit will execute any anonymous function in the class during parsing
INHERIT will ignore any anonymous function in the class during parsing (check link)
NOTE
You can develop your own class for example having your utility functions and use it globally by multiple recipes rather than inheriting the class for each class.

Related

When to use a class vs. module extending self in Crystal?

In Crystal, there's two different ways to achieve similar results:
Creating a class...
class Service
def self.get
# ...
end
end
or a module extending self:
module Service
extend self
def get
# ...
end
end
Both can invoke the method get by Service.get.
But when to use a class or a module? What's the difference between Crystal's classes and modules?
There is not much difference between class and module regarding definition of class methods. They are however fundamentally different in the fact that a class defines a type that can be instantiated (Service.new). Modules can have instance methods as well, but they can't be instantiated directly, only included in a class.
If you only need a namespace for class methods, you should use module. class would work fine for this too, but conveys a different meaning.
Btw: While you can't extend or include a class, in a module you can write def self.get instead of extend.
But when to use a class or a module?
Use a module. In this way a module can be used as a namespace.
What's the difference between Crystal's classes and modules?
A module cannot be instantiated, and can be included inside a class
See: Modules documentation

What is the 'open' keyword in Swift?

The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228:
extension NSObject : Equatable, Hashable {
/// ...
open var hashValue: Int {
return hash
}
}
What does open var mean in this context, or what is the open keyword in general?
open is a new access level in Swift 3, introduced with the implementation
of
SE-0117 Allow distinguishing between public access and public overridability
It is available with the Swift 3 snapshot from August 7, 2016,
and with Xcode 8 beta 6.
In short:
An open class is accessible and subclassable outside of the
defining module. An open class member is accessible and
overridable outside of the defining module.
A public class is accessible but not subclassable outside of the
defining module. A public class member is accessible but
not overridable outside of the defining module.
So open is what public used to be in previous
Swift releases and the access of public has been restricted.
Or, as Chris Lattner puts it in
SE-0177: Allow distinguishing between public access and public overridability:
“open” is now simply “more public than public”, providing a very simple and clean model.
In your example, open var hashValue is a property which is accessible and can be overridden in NSObject subclasses.
For more examples and details, have a look at SE-0117.
Read open as
open for inheritance in other modules
I repeat open for inheritance in other modules.
So an open class is open for subclassing in other modules that include the defining module. Open vars and functions are open for overriding in other modules. Its the least restrictive access level. It is as good as public access except that something that is public is closed for inheritance in other modules.
From Apple Docs:
Open access applies only to classes and class members, and it differs from public access as follows:
Classes with public access, or any more restrictive access level, can
be subclassed only within the module where they’re defined.
Class members with public access, or any more restrictive access level, can
be overridden by subclasses only within the module where they’re
defined.
Open classes can be subclassed within the module where they’re defined, and within any module that imports the module where
they’re defined.
Open class members can be overridden by subclasses
within the module where they’re defined, and within any module that
imports the module where they’re defined.
Open is an access level, was introduced to impose limitations on class inheritance on Swift.
This means that the open access level can only be applied to classes and class members.
In Classes
An open class can be subclassed in the module it is defined in and in modules that import the module in which the class is defined.
In Class members
The same applies to class members. An open method can be overridden by subclasses in the module it is defined in and in modules that import the module in which the method is defined.
THE NEED FOR THIS UPDATE
Some classes of libraries and frameworks are not designed to be subclassed and doing so may result in unexpected behavior. Native Apple library also won't allow overriding the same methods and classes,
So after this addition they will apply public and private access levels accordingly.
For more details have look at Apple Documentation on Access Control
open come to play when dealing with multiple modules.
open class is accessible and subclassable outside of the defining module. An open class member is accessible and overridable outside of the defining module.
open is only for another module for example: cocoa pods, or unit test, we can inherit or override

Choose between abstract class and interface

Among my two processes' functionality, there is a common function to merge files. I need not going to insist any of the processes to have some methods as interface does. And, also the two processes are independent. So, is it fine I just go with an Abstract class and have the implementation in that abstract class itself? Also I do not need any abstract method.
Inheritance is used when there is IS-A relation between subclass and the base class. I don't think it is the case here. You didn't specify the language, but from your profile I guess you use Java. So if you use an Abstract Class you won't be able to inherit from other, more appropriate class in the future.
Instead of inheritance you can use composition. Which means that you create a regular file merging class which has this method to merge files. And in classes where you want to have this functionality you just instantiate this new file merging class. It lets you inherit from other class in the future.
If you want to inform the world that those classes can merge files (to use polymorphism), and you use Java 8 you can create default method inside an interface and implement this interface without override this default method. But I think composition will be better in this case.

base class pointing to inherited class

I have an inherited class which i would like to point to from the base class. Example below
class Base
{
inherited* test;
};
class inherited: Base
{
};
the purpose of this is so that the base class (a character) contains a linked list of the inherited class (items)
ps apologies for any mistakes, i'm new to this site
It might be possible to trick the compiler into accomplishing this, but it's most certainly bad OOP design. If all you want to do is be able to store an instance of the inherited class but can treat it like the base class, then you can simply make inherited* test a base* test and it will accept pointers to either inherited or base (or any other subclass of base).
If you actually want base to treat that instance as inherited, you need to rethink your class hierarchy because you don't actually have an inheritance tree here.

How can a JVM decide if a class “belongs” (e.g. inner or nested classes) to another class?

I want to understand class files and inner/nested classes a bit better and I'm wondering about the following things:
Is the InnerClasses attribute used to refer tothe inner/nested classes in the ´containing´ class or is it used in the inner/nested classes to refer to the ‘container’ class?
Is the InnerClasses attribute in class files sufficient? E.g. Do inner/nested classes have to follow the name mangling with $ or is this just a convention?
Is there a way to make a class look like an inner/nested class to the JVM without setting the InnerClasses attribute and does this depend on the JLM vendor? (I remember hearing that IBM's implementation had less strict requirements in some parts.)
How much does the class loading mechanism of the JVM interact with Java reflection? Would it be possible to make the JVM disagree with the results from Java reflection?
I tried looking it up in the JVM specification but didn't find a description of the actual mechanism.
I only found this sentence in “The InnerClasses Attribute” remotely connected to my question:
The Java virtual machine does not currently check the consistency of
the InnerClasses attribute with any class file actually representing a
class or interface referenced by the attribute.
A few additions to the previous answer:
Is the InnerClasses attribute used to store the contained inner/nested classes in the containing class or is it used in the inner/nested classes to refer to the ‘container’ class?
The bytecode of every compiled class is stored in a separate .class file. The the actual "inner classes" are not stored in that attribute. As the previous post pointed out, that attribute only points to classes that the compiler knew about when creating the bytecode.
Is the InnerClasses attribute in class files sufficient? E.g. Do inner/nested classes have to follow the name mangling with $ or is this just a convention?
Is there a way to make a class look like an inner/nested class to the JVM without setting the InnerClasses attribute and does this depend on the JLM vendor? (I remember hearing that IBM's implementation had less strict requirements in some parts.)
For both questions, I am not certain. But I think the concept of inner/nested classes is something that the Java language (and hence the Java compiler provides). In the bytecode, there should not be any difference between a class that was declared as a normal public class and some nested or inner class.
You could easily try out how an given VM handles this like so:
Create a class with some nested and inner classes
Write a little program that tries to load and instantiate one of the inner classes through reflection from outside the scope of defining class. You must use reflection here, because the Java compiler will not allow you to instantiate a nested class that is not in scope! If you can successfully instantiate the class, that is evidence that internally the VM does not handle nested and normal classes differently.
How much does the class loading mechanism of the JVM interact with Java reflection? Would it be possible to make the JVM disagree with the results from Java reflection?
I don't understand this last question. Could you explain a bit more what you mean when you say the VM and reflection should disagree?
I know that there is an inner class attribute in class files, but is this sufficient?
The InnerClasses attribute is in the byte code and it lists all the known inner classes of the outer class. This is not something you can use directly.
E.g. Do inner/nested classes have to follow the name mangling with $ or is this just a convention?
The compiler will follow this convention and you have no control over it.
Is there a way to make a class look like an inner/nested class to the JVM without setting the inner class attribute and does this depend on the JLM vendor? (I remember hearing that IBM's implementation had less strict requirements in some parts.)
You can create a class with the same name. YOu cna try that for yourself.
How much does the class loading mechanism of the JVM interact with Java reflection?
I don't believe the class loader uses reflection. However reflection may get its information from the same place the class loader does. I don't see why it would matter.
Would it be possible to make the JVM disagree with the results from Java reflection?
You can use reflection to corrupt the data in reflection based objects. Again, not sure why you would want to do this.