I got an email from Google about unsafe implementation of TrustManager
with the only clue that the problematic code is in com.b.a.af class. Clearly that's the obfuscated name. How would I get the real class name from that obfuscated class name, in my own source code. Is there any way to lookup the mapping that ProGuard does? Thanks!
If you have the mappings each class should look like this:
me.vader.event.EventMouseClick -> f:
int buttonID -> q
boolean mouseDown -> r
void <init>() -> <init>
void fire(int,boolean) -> a
int getButtonID() -> n
You can see the obvious before -> after convention. So finding the original names should be really easy.
This isn't really a serious OOP question, just want to get an opinion on the best way to take for my program.
Simple really: Let's say I have an employee class, and that class has the variables and methods that make up an employee.
My question is how would I store an 'employee data'(Data, not Object); It IS SIMPLE, I could just make a JOHN class that extends EMPLOYEE and add data there.
But I've read(actually not sure where) storing simple data in classes is not good?? Because if you extend a class, you should also add other functions in it.
Is there a disadvantage in the solution I proposed? Or is there a better way to 'store' data. NOTE: Assume I cannot open external files and I must add whatever Data I have in the code.
OK:
1) A "class" is a "template" for creating "objects".
A class doesn't contain any data - a class instance (a.k.a. an "object") contains data.
2) An instance of "Employee" might be an object with a member name (member data) of "John".
You wouldn't "extend" Employee to create "John"; you'd create an "object" with the name "John".
3) You might, however, extend employee for a "Manager" class.
4) To answer your original question, of course a "class" can be designed to hold "data". And every object of that class will contain that data.
I'm having a class with several subclasses that all uses methods and fields from the parent-class. Is there a "correct" way of handling this?
So far I've been using (inherit method1 method2 ...) in each subclass.
I've searched in vain for a way that the parent-class can force the subclasses to inherit the bindings, and I understand that that might be bad style.
Not very experienced with Racket or OOP.
The methods are inherited even if you don't use inherit.
To call a method from a super class, one can use (send this method arg1 ...).
The form (inherit method) inside a class form will make the method available in form (method arg1 ...) inside the body. This is not just a convenient shorthand, but is also more efficient than (send this method).
I am unaware of forms that package names to inherit, but you can roll your own with a little macro. Here is an example:
(define-syntax (inherit-from-car stx)
(datum->syntax stx '(inherit wash buy sell)))
(define car% (class object%
(define/public (wash) (display "Washing\n"))
(define/public (buy) (display "Buying\n"))
(define/public (sell) (display "Selling\n"))
(super-new)))
(define audi% (class car% (super-new)
(inherit-from-car)
(define/public (wash-and-sell)
(wash)
(sell))))
(define a-car (new audi%))
(send a-car wash-and-sell)
I got a list of Objects of class-type B (B inherits from A).
How can I downcast all the B-objects to A-objects without using a function to pull the needed information and create a new instance?
(defclass A () ( (varI :initarg :varI :accessor varI) ) )
(defclass B (A) ( (varII :initarg :varII :accessor varII) ) )
(defun generate-list-of-type-B-objects () (....does...some..stuff....))
(defvar *listoftypeA* (generate-list-of-type-B-objects) )
(I know this example is easy to rewrite, as I could make the method generate a list of type A objects, but the function is used somewhere else where type-B objects are needed, and I do not want to duplicate code)
If you absolutely must convert your instances of class B into instances of class A, you can do a one-way conversion of them with the use of CHANGE-CLASS. This is a non-reversible change of each instance.
Since I am not 100% sure what you actually want, the best suggestion I can give is "have you tried leaving them as class B and see if it works?"
Chances are that it will just work, unless you have methods of a generic function somewhere that treat instances of class B differently than instances of class A. If it's only about dropping the space that the extra slot would take, have you measured that it's actually worth it (it probably isn't, unless you have several thousands of instances of class B, where you could get by with instances of class A).
I'm wondering if there's any relatively easy way to extend NHibernate to support F#'s discriminated union. Not just a single IUserType or ICompositeUserType, but something generic that I can re-use regardless of the actual contents of the DU.
For example, suppose I have a property called RequestInfo, which is a union defined as:
type RequestInfo =
| Id of int
| Name of string
This compiles into an abstract RequestInfo class, with concrete subclasses Id and Name. I can get all this info out just fine with F# reflection. In this case, I could store it in the database with "RequestInfo_Tag", "RequestInfo_Id", "RequestInfo_Name".
As I'm a NHibernate newbie, what kind of problems am I going to run into trying to follow this approach? Are more complex cases going to be impossible to deal with? For example, what about nested discriminated unions? Is there a way I can "hand off" the reading of the rest of the union to another ICompositeUserType?
More importantly, will this mess up my querying capabilities? Meaning, will I have to know the actual column names in the DB; I won't be able to do Criteria.Eq(SomeDiscUnion) and have it all sorted out?
I'm not looking for a complete "provide code" answer, just some general advice if this is even worth going after (and some pointers on how), or if I should just rethink my model.
Thanks!
P.S. Not to be rude, but if your answer consists of "use C#", it's not very helpful.
I've not been brave enough to try using NHibernate with F#'s type system, but it might help to look from the perspective of what's actually generated by the F# compiler.
If you look at your Discriminated Union in reflector, there are actually three classes generated (and more if you count the private debug proxies).
public abstract class RequestInfo : IStructuralEquatable, IComparable, IStructuralComparable
The first class, RequestInfo, is abstract, and is actually implemented by the other types in the union.
// Nested Types
[Serializable, DebuggerTypeProxy(typeof(Program.RequestInfo._Id#DebugTypeProxy)), DebuggerDisplay("{__DebugDisplay()}")]
public class _Id : Program.RequestInfo
{
// Fields
[DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated, DebuggerNonUserCode]
public readonly int id1;
// Methods
[CompilerGenerated, DebuggerNonUserCode]
public _Id(int id1);
}
[Serializable, DebuggerTypeProxy(typeof(Program.RequestInfo._Name#DebugTypeProxy)), DebuggerDisplay("{__DebugDisplay()}")]
public class _Name : Program.RequestInfo
{
// Fields
[DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated, DebuggerNonUserCode]
public readonly string name1;
// Methods
[CompilerGenerated, DebuggerNonUserCode]
public _Name(string name1);
}
so when you do:
let r=Id(5)
let s=Name("bob")
r and s are instances of _Id and _Name, respectively.
So the answer to your question is likely the answer to one of the following questions:
How do I map to an abstract class in nhibernate?
How can I make NHibernate use a factory method?
How can I create map Nhibernate to immutable objects?
How do I do implement a custom type in NHibernate (presumably with IUserType).
Unfortunately, I'm not savvy enough to give you a coherent answer to any of those, but I'm sure someone else here has done at least one of these three solutions.
I'd like to think that you can use the same methods used for Inheritance Strategies, using, for example, a discriminator column, but I'm afraid the lack of a default constructor makes this problematic. So I'm inclined to think that using a custom type is the solution.
After some fiddling, here's a (possibly buggy and or broken) custom user type:
type RequestInfo =
| Id of int
| Name of string
type RequestInfoUserType() as self =
interface IUserType with
member x.IsMutable = false
member x.ReturnedType = typeof<RequestInfo>
member x.SqlTypes = [| NHibernate.SqlTypes.SqlType(Data.DbType.String); NHibernate.SqlTypes.SqlType(Data.DbType.Int32); NHibernate.SqlTypes.SqlType(Data.DbType.String) |]
member x.DeepCopy(obj) = obj //Immutable objects shouldn't need a deep copy
member x.Replace(original,target,owner) = target // this might be ok
member x.Assemble(cached, owner) = (x :> IUserType).DeepCopy(cached)
member x.Disassemble(value) = (x :> IUserType).DeepCopy(value)
member x.NullSafeGet(rs, names, owner)=
// we'll use a column as a type discriminator, and assume the first mapped column is an int, and the second is a string.
let t,id,name = rs.GetString(0),rs.GetInt32(1),rs.GetString(2)
match t with
| "I" -> Id(id) :> System.Object
| "N" -> Name(name) :> System.Object
| _ -> null
member x.NullSafeSet(cmd, value, index)=
match value with
| :? RequestInfo ->
let record = value :?> RequestInfo
match record with
| Id(i) ->
cmd.Parameters.Item(0) <- "I"
cmd.Parameters.Item(1) <- i
| Name(n) ->
cmd.Parameters.Item(0) <- "N"
cmd.Parameters.Item(2) <- n
| _ -> raise (new ArgumentException("Unexpected type"))
member x.GetHashCode(obj) = obj.GetHashCode()
member x.Equals(a,b) =
if (Object.ReferenceEquals(a,b)) then
true
else
if (a=null && b=null) then
false
else
a.Equals(b)
end
This code could surely be made more generic, and should probably not be in your actual domain layer, but I thought it would be useful to take a stab at a F# implementation of IUserType.
Your mapping file would then do something like:
<property name="IdOrName" type="MyNamespace.RequestInfoUserType, MyAssembly" >
<column name="Type"/>
<column name="Id"/>
<column name="Name"/>
</property>
You probably can get away without a column for "Type" with a slight tweak to the custom UserType code.
I don't know how these custom user types work with queries/ICriteria, as I haven't really worked with custom user types much before.