Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

understanding the logic of class object name repeats twice question

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,505
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,114
Hello,when i create and object of type class i need to write as shown bellow.
I understand the left side of the line
Code:
TestClass1 f = new TestClass1();

but why we duplicate the same name "new TestClass1();"
What will happen if i will do?
Code:
TestClass1 f = new TestClass2();

Thanks.
 

Hi,

I´m no expert in this, but I explain how I understand it:

an example:
on a PC there is a USB bus. So the user can connect a device to the USB.

Let´s do an example with an USB_Stick:

The SW developer creates one class for an USB stick that contains functions to read, write and so on , and it also allocates memory space for data chache, transfer buffers ....

So a soon as the user connects a stick ... during runtime .. the software calls for a new class USB_stick.
Now one can access to the USB stick.

But now the user connects a second USB stick. Thus the software calls the same (but another "new") class USB stick. Now one can access to both sticks independently.

But after some time the user disconnects the first USB stick. Thus the software closes the first class USB stick and releases the allocated memory.

So the benefit of the classes is, that one has to write one common class and the class can be activated many (copies) times and can be released randomly at run time. This saves code and data memory space.

In opposite:
Without the use of classes you have to write USB_Stick drivers and limit the number of USB sticks (maybe to 8) and the software needs to allocate fix data memory space for all 8 USB devices - independent whether they are used or not.

Again, I'm not 100% sure I got that right. Perhaps there is an expert who has more solid information.

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top