Having the following package hierarchy:
limited private with Root.Child;
package Root is
type Root_t is tagged private;
procedure p_dispatcher (this : in out Root_t);
private
type ChildWideAcc_t is access Root.Child.Child_t;
type Root_t is tagged
record
ref : ChildWideAcc_t;
end record;
end Root;
private package Root.Child is
type Child_t is abstract tagged private;
procedure p_opExample (
this : in out Child_t;
Context : in out Root.Root_t
);
private
type Child_t is abstract tagged null record;
end Root.Child;
I understand that a child package with's automatically it's parent's spec, and a private child package the private part also, but if I do not write any "use" statement on the child I can write too "Root_t" for the "Context" argument type for the procedure "p_opExample" and my program is running exactly the same, like this:
procedure p_opExample (
this : in out Child_t;
Context : in out Root_t
);
Is this behaviour ok? Why?
Since Ada83 it has been possible to nest package definitions within package definitions. An example of nested package structure is the package Ada.Text_IO.
Ada95 introduced the ability to define child packages, which are logically the same as nested packages but are written in a separate file from the parent package. Since they are logically the same the public part of a child package is logically nested within the public part of its parent package and has direct visibility to all the entities declared in the public part of the parent package. The private part of a child package is logically nested in the private part of the parent package and has direct visibility to all the entities declared or defined within the both the public and private parts of the parent package. The child package body is logically nested within the parent package body and has direct visibility to all entities defined in the parent package public region, the parent package private region and the parent package body.
It is therefore not necessary to append the parent package name to an entity defined in the parent package and used in a child of that parent package.
The shared visibility of parent and child packages is not like visibility acquired through the use of a context clause (with and use). A context clause only provides visibility to the public part of a package.
Related
I must turn a Flex code into an Apache Royale one but in my research, there is on attribute for which i dont find the equivalent.
In Flex, to call an actionScipt function from a parent mxml, I have:
<mx:Button label="Login" click="parentDocument.myfunction()"/>
I found parentComponent during my research, but i have Access of possibly undefined property parentComponent error.
I also tried just 'parent' and the error became Call to a possibly undefined method verif_sharedobject through a reference with static type IParent.
I did some research about IParent, Container and Group (From jewel) but for the moment I have no success
please check ParentDocumentBead bead from Core library.
From asdoc :
* The ParentDocumentBead class looks up the parent
* chain to find a parent that was written in MXML.
* Because it is usually rare for an application
* to need to know this information, an optional bead
* is used to compute it, instead of baking in the
* overhead of a recursive infrastucture to store
* this information. It is intended to be used
* as a bead in the top-level tag of an MXML document.
HTH
I learned that there is a public part and a private part in an Ada specification file (*.ads) and only the public part should be considered of the user of the compilation unit (usually a package).
It is actually not usual to separate the public and private part of the specification in different files?
So, finally, the user of such a package knows about the internals of the packages on specification layer but can not use it. Am I right here?
Thanks and cheers,
Wolfgang
No, Ada does not allow you to separate the public and private part of a package specification.
The original chief designer of Ada, Jean Ichbiah, did some work on a language, which actually separated the public, private (data structure) and implementation parts of a package, but this didn't become a part of Ada.
Also:
The private part and body of a child package can see the private part of its parent.
The specification of a private child package can see the private part of its parent.
... so you can't always just ignore the private part of a package specification completely.
A practical example:
When I write unit-tests, I like to put the test suite in a child package of the package I am testing. That way my test cases are not limited to inspect the public view of the types declared in the package.
I am having a configuration object in my flex3.5 application. I want that object to be unmodifiable so that no one can change any property in it once it is created.
If you're talking about a generic Object, it's impossible since it's dynamic. What you want to do is create a class that has only 'getter' functions and every property is specified in the constructor.
If you want to have it still bindable, look at my blog post about bindable read-only properties.
Use get/set methods. There is can be two strategies:
Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
If you need to set values from outside you should create set-methods and throw an error if value already set.
I've have a workflow whose root activity is a custom NativeActivity with a public InArgument called XmlData. When I try and use this argument in a child If activity I get the following error using XmlData within the condition:
'XmlData' is not declared. It may be inaccessible due to its protection level
My properties look like this:
public Activity Body {get;set;}
public InArgument<CustomObj> XmlData {get;set;}
and this is the CacheMetadata method:
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
var runtime = new RuntimeArgument("XmlData",typeof(CustomObj),ArgumentDirection.In,true);
metadata.Bind(this.XmlData,runtime);
metadata.AddArgument(runtime);
metadata.AddChild(Body);
}
I'm adding the argument inside CacheMetadata using the metadata.AddArgument method, and I've tried adding the child property it has using both AddChild and AddImplementationChild.
If I replace my custom activity with an ActivityBuilder and use code to create a DynamicActivityProperty then the condition can be compiled successfully, so I don't see what I'm missing when I use my own code.
There are 3 possible solutions I can think of, one is daft, one is hacky and the other vaguely sensible.
Solution 1 (the daft one)
Promote the RuntimeArgument to a private readonly member and swap the Bind and AddArgument calls around, I've had a few random occurances where this has helped.
Solution 2 (the very hacky one)
You can always put the values in a named property on the context and pull it out in the child
Solution 3 (the sensible one)
If you want to pass the InArgument to a child, bind it to a variable and bind the child to the variable.
Any of those help?
John
I apologize if that title is confusing. This question may be a result of lack of coffee and/or sleep, but my mind is not working correctly right now.
Anyways, I have an inheritance tree like so (I know the architecture isn't ideal):
BaseClass
GeneralForm : Inherits BaseClass
SpecificForm : Inherits GeneralForm
And an object like so:
MyItem
MySpecificItem : Inherits MyItem
I have Items As List (Of MyItem) as a property in BaseClass. I would like for SpecificForm to somehow override Items to return type List (Of MySpecificItem). I feel like this is easy to do, but again, my head is spinning and I can't think straight at the moment.
Thanks so much in advance.
EDIT
If the above isn't possible, is it possible to take a List (Of MyItem) and turn it into a List (Of MySpecificItem)? MySpecificItem has just one additional property that is specific to SpecificForm, but I NEED it.
Anyone? :\
You should be able in SpecificForm to just do the following...
Private pMySpecificItems As List(Of MySpecificItem)
Public Shadows ReadOnly Property Items() As List(Of MySpecificItem)
Get
Return pMySpecificItems
End Get
End Property
The 'Shadows' keyword will tell the compiler that this property in SpecificForm hides the Items property from the base-class form.
You can't actually delegate to the base class' property and "cast" it to List(Of MySpecificItem) because while a sub-class may be viewed as an instance of its base class, a base class object cannot be cast to an instance of a sub-class (as the sub-class may have added required properties/state that the base class does not support or implement).