In Etherreum Quorum, can a private contract invoke another private contract shared with a different set of participants? - quorum

Let's say I have the following four nodes
Node A
Node B
Node C
Node D
And the following three smart contracts
Smart contract AB (private to A & B)
Smart contract BC (private to B & C)
Smart contract ABD (private to A, B & D)
Can either smart contract AB or BC invoke a method on smart contract ABCD as all are marked as private contracts? I know that this cannot be done from Node C as contract ABD does not exist on node C. But can this work from nodes A or B?

Related

VB.NET make method of object accessible only for certain other object

I have declared 2 classes: A and B. They are connected as an object tree: Object A holds a "list of B" as private member variable.
EDIT: I am declaring 3 classes: A, B and C. A holds list of B and B holds list of C.
All my object data is stored in a database (1 table per object).
Each object has a method "delete", which will delete his own database record ("suicide").
B.delete should only be called from A which will then also remove the item from his own "list of B".
I want, that method B.delete can only be invoked internally or by a member of object A.
EDIT: and C.delete can only be invoked internally or by a member of object B.
However other methods in B and C must remain public.
Is this possible?
What would be the declaration / approach / architecture?

Accessing the base part of a derived object

Lets say I am given an object O on some method.
This object O is derived from a base Object BaseClass and as such has a part whose type is BaseClass.
How can I access this part when I am in this method, which means super wont work because I am not in the context of the object.
Thanks!
Let me re-phrase your question to make sure I understand it. You have a class O containing a method (say "test"). In that method, you want to access an instance variable belonging to the superclass BaseClass.
If this is correct, then you can already access that instance variable directly. You just need to provide the name of the variable. Your subclass has access to all of the instance variables visible to the superclass.
You should consider creating get and set methods for the variable and accessing the variable by calling those methods from the subclass, but it's optional.
Let me provide another answer, which could be useful for cases where the question refers to behavior (methods) rather than shape (instance variables.)
Assume you have two classes C and D and an instance c of C. Now assume C inherits from C' and you would like to invoke a method m defined in C' that has been overridden in C. The expression c m will activate the implementation in C rather than the one in C' because c class == C, not C'. As you said, there is no "remote" version of super that you could use from D.
If what you want is to activate the method in C', then you should move the source code of m in C' to another method, say m0, and redefine m in C' so that it just delegates to m0 (^self m0). Keep the method m in C unchanged and then call from D using m0 (c m0) instead of m (c m).
Note that the other way around will not work: if you define m0 in C' as ^self m, the expression c m0 will activate the version of m found in C, not C'.
You could also define m0 in C as ^super m and that way c m0 will activate C'>>m. However, the usage of super with a different selector is not considered a good practice, and you should chose not to do that.

How does High Cohesion help us reduce Coupling?

Assume methods M1 and M2 have strongly related responsibilities
First example:
If
• M1 and M2 are defined within class A ( thus class A is highly cohesive )
• class B uses A.M1 and class C uses A.M2
then
• A is coupled with both B and C classes
• changing the signature of M1 will require changes only in B, but not in C
Second example:
If
• M1 is defined within class A1 ( thus B is coupled with A1 )
• M2 is defined withing class A2 ( thus C is coupled with A2 )
then
• changing the signature of M1 will require changes only in B, but not in C
a) To my understanding, classes in last example are no more coupled than classes in first example! Or am I missing something?
b) As far as I can tell, classes in first example are more loosely coupled than those in second example only if:
we assume that changing the signature of M1 will also require us to change the signature of M2, but I don't see that happening very often?!
or if both M1 and M2 operate on the data of same type T1, then replacing T1 with T2 will require changes in both M1 and M2?!
or if we assume that due to M1 and M2 having closely related responsibilities, that the chances are that much greater that changing M1 will often require M2 also to be changed (even if M1 doesn't directly or indirectly call M2)?!
or if we assume that due to M1 and M2 having closely related responsibilities, the chances are much greater that some class will require both M1 and M2 ( as such having M1 and M2 in single class reduces coupling )?!
c) Are there any other reasons why defining M1 and M2 within A ( instead of defining M1 within A1 and M2 within A2 ) will reduce coupling?
Note - I'm aware that we should have higly cohesive modules due to easier maintenance and reusability
Thank you
Yes it does. What you are missing that is if ClassA is cohesive, changing M1 will cause ClassB to access some other method in ClassA. It increases maintenance because you won't have to modify other modules (method and variables) in ClassA itself.
When we call a class cohesive (say ClassA) , we mean that we can easily use the purpose(s) of the class without have to make our caller class (ClassB) according to the requirements of ClassA. Hence, ClassB is not dependent on ClassA and thereby cohesion is reduced.
Don't think of think of cohesion in terms of methods. Methods are not called cohesive, classes are.

OO design: Copying data from class A to B

Having the SOLID principles and testability in mind, consider the following case:
You have class A and class B which have some overlapping properties. You want a method that copies and/or converts the common properties from class A to class B. Where does that method go?
Class A as a B GetAsB() ?
Class B as a constructor B(A input)?
Class B as a method void FillWithDataFrom(A input)?
Class C as a static method B ConvertAtoB(A source)?
???
It depends, all make sense in different circumstances; some examples from Java:
String java.lang.StringBuilder.toString()
java.lang.StringBuilder(String source)
void java.util.GregorianCalender.setTime(Date time)
ArrayList<T> java.util.Collections.list(Enumeration<T> e)
Some questions to help you decide:
Which dependency makes more sense? A dependent on B, B dependent on A, neither?
Do you always create a new B from an A, or do you need to fill existing Bs using As?
Are there other classes with similar collaborations, either as data providers for Bs or as targets for As data?
I'd rule out 1. because getter methods should be avoided (tell, don't ask principle).
I'd rule out 2. because it looks like a conversion, and this is not a conversion if A and B are different classes which happens to have something in common. At least, this is what it seems from the description. If that's not the case, 2 would be an option too IMHO.
Does 4. implies that C is aware of inner details of B and/or C? If so, I'd rule out this option too.
I'd vote for 3. then.
Whether this is correct OOP theory or not is up for debate, but depending upon the circumstances, I wouldn't rule C out quite so quickly. While ti DOES create a rather large dependency, it can have it's uses if the specific role of C is to manage the interaction (and copying) from A to B. The dependency is created in C specifically to avoid creating such dependency beteween A and B. Further, C exists specifically to manage the dependency, and can be implemented with that in mind.
Ex. (in vb.Net/Pseudocode):
Public Class C
Public Shared Function BClassFactory(ByVal MyA As A) As B
Dim NewB As New B
With B
.CommonProperty1 = A.CommonProperty1
.CommonProperty2 = A.CommonProperty2
End With
Return B
End Function
End Class
If there is a concrete reason to create, say, a AtoBConverterClass, this approach might be valid.
Again, this might be a specialized case. However I have found it useful on occasion. Especially if there are REALLY IMPORTANT reasons to keep A and B ignorant of eachother.

Less APIs or more encapsulation?

3 class, A contains B, B contains C. So user want to use some service of C, there are two choice:
First, more encapsulation:
class A:
def newMethod(self):
self.b.newMethod()
class B:
def newMethod(self):
self.c.newMethod()
class C:
def newMethod(self):
#do something
pass
a.newMethod()
Call service of c directly:
class A:
pass
class B:
pass
class C:
def newMethod(self):
#do something
pass
b = a.b
c = a.c
c.newMethod()
Generally, what I learned from books told me that 1st choice is better.
But when C has many many methods to expose to outer user, 2nd choice seems to be more reasonable. And in the first design, A and B did nothing really useful.
What will you choose?
Get your objects to do things for you, rather than asking them for their data and doing stuff with it.
If c in your example is exposing a lot of methods, I would suggest that you shouldn't be exposing these to a and your clients, but rather a and b should be working together to use these methods on behalf of the client.
A good indicator of a problem is a class that contains data, and provides getters for those data items, and the client code accessing that data and then performing work (DAOs excepted). In this (common) scenario the class most likely shouldn't be exposing that data (and perhaps breaking encapsulation), but rather doing the work for that client (either by having that functionality, or perhaps some injectable strategy object).
Check out the Law of Demeter (the linked document looks rather dry and academic, regrettably), which offers some good guidelines as to how objects and members should communicate.