Call method from this class to another that just call - call

I have classA and classB
in class A I call create classB like this:
classB b = new classB();
b.method();
in class B, I want to call back to class A when method done
How can I do that, please help me!!!

What would you like to call back exactly to class A? A simple solution(and maybe not the best) would be to use a global variable because both class A and class B are in class A. You could also instantiate a class A variable in class B and create a method in class A that sends some variable back to Class A once a method in Class B is done such as:
In classB:
classB b = new classB();
classA a = new classA();
b.method();
a.sendResultToClassAMethod(some variable);
In classA:
method sendResultToClassAMethod(some variable){
this.variable = variable;
}
I hope this helps

Related

mypy TypeVar include bound class as well as subclasses

class Super:
#classmethod
def instantiate(cls) -> What goes here?:
return cls()
class Sub(Super):
pass
class Sub2(Super):
pass
When writing typehints, what's the canonical way to say a method should return an instance of the super class or any of its subclasses. Closest I could find is TypeVar("Super", bound="Super") but this still raises an error for the Super class in mypy
here you can use typing.Type to type-hint cls like this:
from typing import TypeVar, Type
C = TypeVar("C")
class Super:
#classmethod
def instantiate(cls: Type[C]) -> C:
return cls()
class Sub(Super):
pass
class Sub2(Super):
pass
reveal_type(Sub.instantiate()) # note: Revealed type is 'tmp.Sub*'
reveal_type(Sub2.instantiate()) # note: Revealed type is 'tmp.Sub2*'

systemverilog static class member cannot be accessed via the class scope resolution operator

In my t1 extended uvm_test class I'd like to use the xxx_write method from a sequence class xxx_io in xxx_pkg.
I've imported * the package into my t1 class, and I've made the method static but I still receive the same error from compiler:
ncvlog: *E,ILLCSS (/ddd/test.sv,82|29): A Non static class member cannot be accessed via the class scope resolution operator '::'.
xxx_pkg::xxx_io::xxx_write(12'h000, 32'h11ceb00c);
Since the error message did not change after I added the static key word to xxx_write method it would not surprise me if the error is elsewhere. But my code 'works' if I do not try to call this method from t1 class.
package xxx_pkg
class xxx_io extends uvm_sequence #(xxx_seq_item);
static task xxx_write( bit [11:0] i_addr, integer i_wdata );
// snip other code
endtask
endclass: xxx_io
endpackage: xxx_pkg
class t1 extends uvm_test
import xxx_pkg::*
class test1 extends uvm_sequence #(xxx_seq_item);
task body ;
xxx_pkg::xxx_io::xxx_write(12'h000, 32'h11ceb00c);
// snip other code
endtask
endclass : t1
From Greg: create an instance of the sequence in the test then call the method from that instance

Use of Wrapper class for deserialization in callout?

I found the following use of a wrapper class, and was wondering if it is a good practice or whether its just duplication of code for no reason.
//Class:
public class SomeClass{
public Integer someInt;
public String someString;
}
//Callout Class:
public class CalloutClass{
public SomeClass someMethod(){
//...code to do a callout to an api
SomeClass someClassObj = (SomeClass)JSON.Deserialize(APIResponse.getBody(), SomeClass.class);
return someClassObj;
}
}
//Controller:
public class SomeController {
public SomeController(){
someClassObj = calloutClassObj.someMethod();
SomeWrapper wrapperObj = new SomeWrapper();
for(SomeClass iterObj : someClassObj){
wrapperObj.someWrapperInt = iterObj.someInt;
wrapperObj.someWrapperString = iterObj.someString;
}
}
public class someWrapper{
public Integer someWrapperInt{get;set;}
public String someWrapperString{get;set;}
}
}
The wrapper class "someWrapper" could be eliminated if we just use getters and setters ({get;set;}) in "SomeClass."
Could anyone explain if there could be a reason for following this procedure?
Thanks,
James
My assumption (because, code in controller is extra pseudo) is
SomeClass is a business entity, purpose of which is to store/work with business data. By work I mean using it's values to display it (using wrapper in controller), to calculate smth in other entities or build reports... Such kind of object should be as lightweight as possible. You usually iterate through them. You don't need any methods in such kind of objects. Exception is constructor with parameter(s). You might want to have SomeObject__c as parameter or someWrapper.
someWrapper is a entity to display business entity. As for wrapper classes in controllers. Imagine, that when you display entity on edit page and enter a value for someWrapperInt property, you want to update someWrapperString property (or you can just put validation there, for example, checking if it is really Integer). Usually, as for business entity, you don't want such kind of functionality. But when user create or edit it, you may want smth like this.

List of static methods from an instance in ExtJS

I have an instance of a class (e.g Ext.data.Model) myRecord and need to call one of its static methods (e.g getFields()). How can I do that?
You can also use the self property to get the class:
myRecord.self.getFields();
You need the class of that instance and then simply call the static method.
E.g:
var myClass = Ext.ClassManager.getClass( myRecord );
myClass.getFields();

How to define recursive Property in Castle ActiveRecord?

Suppose you have a class named MyClass. MyClass should have a property named Parent, Parent must be of type MyClass itself. It is necessary because MyClass wants to hold a tree structure.
How can it be done?
It's pretty straightforward:
[ActiveRecord(Lazy = true)]
public class MyClass {
[BelongsTo]
public virtual MyClass Parent { get;set; }
}
You might also want to map the collection of children.
See these articles for more information on how to run recursive queries over this:
http://ayende.com/Blog/archive/2006/11/22/ComplexQueriesWithActiveRecord.aspx
http://web.archive.org/web/20090806071731/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/05/14/how-to-map-a-tree-in-nhibernate.aspx
http://ayende.com/Blog/archive/2009/08/28/nhibernate-tips-amp-tricks-efficiently-selecting-a-tree.aspx

Resources