I'm writing some documentation and I just can't find the right word. Let say my class is called Writer and some people will be using it. How should I name objects that use the class (or instances of) I'm documenting?
Users of Writer class? - Program is not "a user".
Consumers of Writer class? - Sounds like somebody will eat it.
Callers or Writer class? - Sounds good for methods only.
There must be a correct word for this and I should feel stupid for asking but please, help.
Edit: just to clarify, I'm thinking about the code (not programmer) that is calling and using the class or instance of it (well, maybe I'm thing in code to much...)
I will prefer user anyway, even it is not a end-user. When you write documentation for your code the target audience is a programmer that will use your code. That programmer and their programs are users of your code.
How about "Client"?
First of all, know that there are no stupid questions, just stupid answers.
An End-User (the developer in this case) would be the user of the class.
Consuming is a verb related to aquiring resources.
Indeed calling is for functions.
Well, in the classic book Thinking in Java 2nd edition, there are two ways of using a class: by composition or by inheritance.(yes, this bit is also important)
I don't remember the exact words, but the summary would be sort of like this:
composition - you create a new object from which the target class instance would be referred.
inheritance - you create a new class that inherits (extends) the target class, provided that class is able to be inherited from.
For the exact terminology, I would say it really doesn't matter that much.
But if you want just describe the case where a new instance of such a class is created, you could say some actor (user) instantiates a new object of this class.
Hope this helps.
Edited : the terminology really depends if you think it is the user or the user's code that makes use of the target class.
Related
We can expose an object of a class by two methods like:
ClassName obj=Classname(); or obj=Provider.of<ClassName>(context);
is there any difference between them , or is there anyone of them better method.
ClassName obj = Classname();
This is creating a new instance of Classname. In Dart, you can omit the new keyword (since v2.0), older versions and most other languages actually force you to spell it out:
ClassName obj = new Classname();
It will call the constructor of the class and create a new instance. Alternatives would be named constructors that could look like this:
ClassName obj = Classname.fromInt(42);
That said, what exactly is this and what is the difference:
obj = Provider.of(context);
A provider is a form of state management. State management is a complex way of saying "where do I actually call my constructors so that the instances are known to the program at the place and time I need them? Sometimes I want a new instance, sometimes I want the instance I used before."
A provider may create a new instance for you. It may also decide it already has the instance you are looking for. You decide that by configuring it.
The only way to create a new instance of a class is through one of it's constructors. Very likely (but configurable), a provider is using a class constructor to create the instance of a class that it is then providing to multiple layers of your program so you don't have to keep track of that variable yourself.
Keeping track of all your variables and their lifetimes by yourself gets complicated really fast the bigger your program gets.
My personal recommendation to everyone learning programming is: try it the way you already know (in this case: constructors). Then you will experience for yourself what the problem is and you will know why packages like provider or bloc were created. This is a much better learning experience than just believing a random person on the internet (me or someone else) who says they know it's "better". Because then you will understand the problem instead of being railroaded into some cargo cult of "use this, it's good for you".
welcome to the StackOverflow.
You can do both of them, but if you are using the Provider package, you have some benefits:
It is much easier to transfer state to another level (or even really far level) inside your app's tree.
It is really suitable for a large scale app to manage their state (but it's also suitable for the small app).
If you are passing a state or an object directly, you'll be completely in a mess when your app complexity grows (based on my experience).
I hope it will be helpful.
listening is not possible with normal object creation where as with provider it is possible.
obj=Provider.of(context, listen:true);
I have a question regarding OOP. I'm not new to Delphi, but I learned it by myself, mostly from the internet and didn't learned it the "correct" way. I just started to take a look at OOP some weeks ago. So this is my problem:
I have an own Class called "Session". This class is connected with Edits through Visual LiveBindings. I want to fill my class with data from a TClientDataset (there is a reason why I don't bind the dataset with the edits directly). Now I have 2 ideas:
1. I build another class which implements the Dataset and handles the opening of files and Navigation.
2. I Drag and drop the ClientDataset one my Form and connect it to my class with Livebindings, like this: DataSet <---> Class <---> Edit
I hope you understand my description. So: Which idea is better? I have the feeling that LiveBindings "destroy" the Concept of OOP. On the other hand I don't need to write Code and typecast, because the live bindings do that for me.
So which way would you choose and why? Or has somebody another idea?
I hope you understand what I mean and can help me :)
With LiveBindings it is perfectly possible to bind to objects instead of datasets.
See: http://www.malcolmgroves.com/blog/?p=1084
In summary: take look at TAdapterBindSource component. It is designed for creating LiveBindings between existing controls and custom objects. In it's onCreateAdapter event you can return a TObjectBindSourceAdapter as aBindSourceAdapter in case you want to bind one specific object, or return a TListBindSourceAdapter for binding list of objects.
LiveBindings and OOP does not bite each other!
From a design point of view, can I say that Interfaces are used to produce flexible code open for future easy maintenance. Referring to the case study, am I right to say:
Interface in this example is used because both Professor and HeadofDept class have the power to employ people. Assuming that we might add other people who might be given the right to employ people in the near future.
Thanks for your attention.
Interface will allow your code to call methods like employPeople() on the base type i.e EmployerProfessor. So you pass around EmployerProfessor objects and code need not know what the exact implementation is, it just knows that it can call employPeople(). So it allows for dynamic dispatch of method calls. Using some compiler implementation (vtable etc) it will call the correct method for you.
Interfaces are not always so flexible, its difficult to go and just change an interface since current code in the wild may be affected. An interface provides a contract, it tells the class implementing it, that you must provide the following methods.
I started writing some code for a 2D game, created a class "objets" trying to keep it as generic as possible. I have a few methods and attributes that are common to every kind of element (buldings, ppl, interface buttons, etc) like (w, h, x, y ...you know) but most of them only make sense when applied to and specific type of item.
So I would have to inherit a new class for every type of actor in the game?
Just wondering if this is a common practice, or maybe i should manage it in a different way.
Thanks in advance.
If you're introducing behaviour then subclass, however if the difference is attribute based then don't e.g.
Animal (has .colour and .makeSound) -> Dog (has .eatOwnPoop) -> RedDog (no, too specific, covered by colour)
Notice how I had ".makeSound" in Animal. I could have put .bark in dog, but then I'd have to put .meow in cat etc. The subclass can simply override and provide a concrete sound.
However, you can use interfaces to better cross-cut your code, but that's quite a lengthy topic and probably overkill for your needs (although it could help any unit testing you do).
It sounds like you are over-using inheritance. It is certainly a red flag when you simultaneously say "common attributes like ..." and "...only make sense when applied to a specific type." Also, it is a red flag that domain objects such as building share a common base class with an interface object like button. Finally, it is quite unusual to define your own objet (object?) class from which every class in your system derives. It's not inconceivable, but in combination with your other comments, it sounds like you've started down an unproductive path.
You might want to refer to a good tutorial on object-oriented design and analysis such as "Head First OOA&D"
You do not HAVE to do anything. Generally, it is useful to use derived classes if they exhibit some kind of commonality but become more specialised in nature requiring specific functionality at each level of inheritance. It is also good to use if you want to have polymorphic behaviour. You have asked a very open ended question but basically do not feel that you HAVE to use inheritance as not every problem requires it and indeed some people overuse inheritance, introducing it in places where it really is not needed. All in all, I would really recommend that if you haven't already that you read a good book on object oriented design as this will then get you to think about your code from a different perspective and greatly improve the way you view software and design it. It may sound like a cop out but this kind of question is very hard to answer without knowing all details of what you are doing.
I have an extremely hard time figurering out how classes needs to communicate with eachother. In a current project I am doing, many classes have become so deeprooted that I have begun to make Singletons and static fields to get around(from what I get this is a bad idea).
Its hard to express my problem and its like other programmers dont have this problem.
Here is a image of a part of the program:
Class diagram
ex1. When I create a Destination object it needs information from Infopanel. How to do that without making a static getter in InfoPanel?
ex2. DestinationRouting is used in everybranch. Do I really have to make it in starter and then pass it down in all the branches?
Not sure if this makes sense to anybody :)
Its a problem that is reacurring in every project.
After looking at your class diagram, I think you are applying a procedural mind set to an OO problem. Your singletons appear to contain all of the behavior which operate on the records in your domain model and the records have very little behavior.
In order to get a better understanding of your object model, I'd try and categorize the relationships (lines) in your class diagram as one of "is-a", "has-a", etc. so that you can better see what you have.
Destination needs some information from InfoPanel, but not likely all information. Is it possible to pass only the needed information to Destination instead of InfoPanel?
What state is being captured in the DestinationRouting class that forces it to be a singleton? Does that information belong elsewhere?
There's just too little information here. For example, I am not even sure if MapPanel and InfoPanel should be the way they are. I'd be tempted to give the decorator pattern a try for what it's worth. I don't know why a Listener is a child of a Panel either. We need to know what these objects are and what system this is.