I want to know if there is such tool that can show my classes hierarchy in a tree, e.g.
public Class ClassA
{
ClassB variableb;
ClassC variableC;
}
so, it shows me something like
ClassA
ClassB
ClassC
I have shown in bullted format, I just want that this kind of things be shown in tree view, is there any tool which can help me create this tree of classes ??
I got the solution in the form of class Diagram, don't why I didnt think of them at first place. :)
Related
Been doing objective-c for 5 years, so please bear with me.
I'm struggling to find documentation that clearly explains why you would want to nest a class definition, inside of another.
If I had two classes like the following, it makes sense to me that they are declared above and below each other. You may even want to have a nested property that references the other.
class DataImporter {
}
class DataGenerator {
}
But I don't understand why a nested arrangement like the following would be useful.
class DataImporter {
class DataGenerator {
} }
You would do that for Namespacing. This way you can have the classes with the same name (like DataGenerator). But for different purposes. This one would be DataImporter.DataGenerator class, but you could have another OtherClass.DataGenerator class which would be a totally different one.
Like in Objective-C when you had 2 or 3 letters before the name of the class (ex: UIView). But when you created your own, it would be like SSView
You can also declare the inner class private and use it just in that file.
I missed a few CS classes, namely the ones going over topics such as polymorphism, inheritence, and abstract classes. I'm not asking you to do my homework but I have no idea where to even start to get further guidance, so giving me a skeleton or something would help me greatly, I'm so confused.
So the problem is to create an employee abstract class with two subclasses, permanentEmployee and TempEmployee.I must store information such as name,department,and salary in these subclasses and then order them according to how the user wants them ordered. I know I start out like this
public abstract class Employee
{
}
public class TempEmployee extends Employee
{
\\variables such as name, salary, etc, here?
}
public class PermEmployee extends Employee
{
\\here too?
}
but I have no idea how to store variables in there much less access them later for ordering and displaying,. Please guidance.
If all you're looking for is an example of class-level data members in Java, this should help:
public class SomeClass {
private int someInt;
public int getSomeInt() {
return this.someInt;
}
public void setSomeInt(int someInt) {
this.someInt = someInt;
}
}
Regarding polymorphism, be aware that methods are polymorphic, but values are not. As you place values and methods (getters and setters) in your base class and derived classes, I encourage you to experiment with these concepts thoroughly. Try moving the entire value/getter/setter to the base class, try moving just the value but not the getter/setter, try putting the value in both and the getter/setter in both, etc. See how it behaves.
Make sure that any value/method/etc. that you put in your base class is applicable to all derived classes. If there's ever an exception to that rule, then you would need to move that member out of the base class and into only derived classes where it applies. Note that you can have a complex hierarchy of base classes to accommodate this if needed.
When it comes time to access these members for sorting/display/etc., consuming code would use the getters/setters. For example:
SomeClass myInstance = new SomeClass();
myInstance.setSomeInt(2);
System.out.println(myInstance.getSomeInt());
I am not sure which language you working with, but as it has "extends" I am sure you are not working with c# or CSharp, it can be Java. So I would recommend you to go for TutorialsPoint. This particular article has abstraction described here.
Just to make it easy for you, in Interface and abstraction we always create a structure or the base, it has all the common things defined or declared (Obviously interface has only methods and no variables can be declared inside it).
So as said, in above example, EmployeeId, EmployeeName, EmployeeAddress ...etc should be defined in the base class that is Abstract Base class Employee, But in TempEmployee you can have a criteria such as EmpTermPeriod, EmpContractRenewalDate, EmpExternalPayrollCompanyName (Have made names long and self descriptive) and PermEmployee to have fields like EmpJoiningDate, EmpConfirmationDate, EmpGraduityDate...etc.
I hope it helps.
First of all, I'm not completely sure how to explain this.
I looked for it in different threads / websites, but I have no idea what to look for
The base class of classA is classB.
ClassA has propertyX, classB doesn't.
When I open the designer for classA, i get this error for classB:
"The type 'classB' has no property named 'propertyX'."
like this:
When I click 'ignore and continue', my designer shows an empty control.
What did I do wrong?
I have a base class and a derived class and I want to export for types derived from either.
So like this
public class ClassA { }
public class ClassB : ClassA { }
I need to load types derived from ClassA but also types derived from ClassB.
var registration = new RegistrationBuilder();
registration.ForTypesDerivedFrom<ClassA>()
.Export<ClassA>();
registration.ForTypesDerivedFrom<ClassB>()
.Export<ClassB>();
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(".", registration));
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly(), registration));
container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this, registration);
I think the problem is that when exporting ClassA derived types it also exports ClassB types which is obvious and is the functionality that I am looking for. But it means that the ClassB imports aren't exported as independent objects, rather being the same ones as those imported as ClassA types. If I don't specifically export the ClassB then any imports using them fail.
I may be trying to do something stupid to try and solve my problem here that MEF isn't liking? I have looked at making the MEF imports non-singleton but that might break things in my imports.
In your given example only ClassB (with the export definition of classA) is exported as a MEF part. As Panos already mentioned, ForTypesDerivedFrom does not export the base class.
You can do something like this:
var registration = new RegistrationBuilder();
registration.ForTypesDerivedFrom<ClassA>().Export();
registration.ForType<ClassA>().Export();
This will export all derived classes of ClassA (also ClassB with ClassB contract and not with ClassA) and separately ClassA.
Additionally if you want to hide the base part but still want to use imports in this class you can add the [PartNotDiscoverable] attribute to your base class.
I've got two view controllers that have some similar function. Some of them are IBActions. Is there a way to put them together(so that it's easier to fix bugs)? I've tried inheritance but it seems that it does not work.
#implementation ClassA
-(IBAction)f
{
//some code here
}
#implementation ClassB
-(IBAction)f
{
//some code here
}
My question is that is there a way that I write function f once? If there is a bug, I could fix it more quickly this way.
in inheritence, you can just declare in parent class, like abstract function, and for each child defination will be separte, now you have to do is this
make a method in parent class that performs the logic only,
make two ibactionn methods both in childs and perform the current child's UI tasks in that methods and use the parent's logic method, that u created above, to get the data.
inform if you get soltion or not.
Make a method that does the job and call it either from the IBAction or wherever you need it.
You can make utility kind of class where you can make class method for this.
And you can call this method where needed.
You Can make another singleton class or utility class as per your requirement. And make class method, for common functionality. So u can use this functionality any where from project.
Its good practice to make utility class or singleton class for some common functionalities.