473,657 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reducing dependencies

Hi,

I know that this is one of the topics that are most popular but I just have
to ask.
Can anyone give me some links, info etc about following question:
- how to reduce code dependencies
- make the code less vurnelable for changes (interfaces?)

Question is becaues I'm starting a new project and I was wandering how to
design classes to make to reduce dependencies.

Also some links with explanation about how exactly compiling work what the
actual difference between global variables and those allocated via 'operator
new'.

This question came up becaues I read that in order to reduce dependencies I
can do something like this:

class CFile;

class CLog
{
CFile *m_pFile

public
..... //code.... ble ble
}

but if I do this I have to dynamically create CFile?

I started to think about It... and I get to conclusion that me C++ skills
are to pure.... to explain myslef what is better
(other option is:)

#include "File.h"

class CLog
{
CFile m_File

public
..... //code.... ble ble
}

this is not only think.... so some good resources about differences in
memory allocation.. (I understand the concept of operator new, but I want to
understand the consequences of it....)
Thanks for any help...

regards,
Slawek
Nov 22 '05 #1
2 1481
Slawek wrote:
Hi,

I know that this is one of the topics that are most popular but I just have
to ask.
Can anyone give me some links, info etc about following question:
- how to reduce code dependencies
- make the code less vurnelable for changes (interfaces?)


Microsoft's COM has a methodology that provides for managging interface
revisions.

All of COM's classes inherit from "IUnknown" and you can convert from
IUnknown to another interface using the QueryInterface method.

This can be achieved using standard C++ mechanisms and I have used them
in non-COM based systems.

Another mechanism is PIMPL. You can look that up on google.
Nov 22 '05 #2
> class CFile;

class CLog
{
CFile *m_pFile

public
.... //code.... ble ble
}


let me try to explain the difference between your two examples:

in the first definition CLog only contains a pointer to CFile, which is
why the type doesn't have to be fully known at declaration time
(forward declaration suffices, no include necessary).

the difference to your latter example, storing an instance of CFile, is
that the compiler knows to work with pointers without complete type
information as long as you don't dereference them (by using ptr->member
or *ptr). e.g. pointers are always the same size, regardless of their
pointee type, so by looking at the above declaration the compiler knows
how to store m_pFile in the CLog binary signature. this is not true if
you store instances, as in your latter example.

imagine that you add a member to CFile during later development. CFile
will grow in memory size because of the new member. CLog's signature
will not change if you chose a pointer to CFile, but it would have had
you chosen to store a CFile instance in CLog. thus, a change to CFile
does not require a recompilation of any classes that store a pointer to
CFile instances, all classes that store the instances themselves have
to be recompiled.

unfortunately tricks like this one or others like the more general
pimpl idiom are only valid if you work with one specific version of one
compiler, as the application binary interface of the implementation may
change over different versions and different compiler vendors do not
guarantee inter-compatibility. this also applies to the STL. you may
want to look into interface specs like CORBA or COM or use C linkage
(extern "C"...) for your visible interfaces if you strive for total
compatibility.

the following kde design doc gives more information on c++ binary
compatibility gotchas:
http://webcvs.kde.org/*checkout*/dev...atibility.html

-- peter

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8105
by: Dan Hartshorn | last post by:
Anybody know if there is a system function that can be used from a stored procedure that determines if a given primary key has existing dependencies? I want to make a check for this and if there are none, I will delete the record. If there are, I will change a field called bitStatus from 1 to 0. Enterprise Mgr. does something like this under All Tasks, Display Dependencies. The normal way I do it is to manually check for the existance of...
14
1750
by: Jason Heyes | last post by:
I have read item 26 of "Exceptional C++" that explains a way of minimising compile-time dependencies and, therefore, a way to improve compile speeds. The procedure involves replacing #include directives with forward declarations from within header files. However, a potentially large number of source files may have previously relied on the removed #include directives being present. Therefore it is likely that a large number of source...
12
2237
by: Stuart MacMartin | last post by:
Looking for tricks for speeding up builds... We have an application with about 970 of our own classes of various sizes plus a fair number of routines. Over the past year the compile/link time has been slowing down on PC (MFC dev studio 6) and on linux. Link time on PC seems to depend on RAM - a new desktop machine with 2Gb of RAM compiles and links significantly faster than a three year old laptop with 1/2 Gb of RAM but same processor...
1
4413
by: mp | last post by:
Hi, I have problem with project dependencies. I have made new setup application and everything works perfectly on my comp with VS 2003. On another computer with VS 2002 it does not work. Normally it does not work on computer without VS framework. I am not sure what proper way is to include dependencies. I know how VS automatically discovering all dependencies and add it to
2
13861
by: JT Lovell | last post by:
I have a solution with 5 projects and I need them to build in a particular order. I understand that setting the project dependencies will allow this, but when I go to the Project Dependencies dialog, the "Depends on" checkboxes are grayed out. Is there something else required in order to enable these? Thanks, -- JT Lovell
7
13512
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time dependencies). But then I started wondering how "easy" it would be to similarly make a NON-RUNTIME circular dependency between (implicitly linked) DLLs. Indeed authors like John Lakos, who focus on compile/link-time dependencies (not run-time),...
6
17009
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project as "Additional Dependencies" under Linker-Input options. Since those libraries are also in different directory, I specified that library path in project as "Additional Library Directories" under Linker-General options. This is where I see some...
8
2376
by: Scott Sauyet | last post by:
I found myself needing to find my way recursively through a document in XSLT, finding the dependencies one element had on others, and including only those in an initial set, their dependencies, the dependencies of those dependencies and so on. I managed to do it, but I'm not really happy with the method, and I'm wondering if anyone can suggest something better. My technique involves manipulating a string containing the names, calling a...
6
5389
by: =?Utf-8?B?YXByMDUyNA==?= | last post by:
I am wondering if there is a devenv switch that will ignore build dependencies that are set in .xxproj files. At the command line I am attempting to build individual projects that I do not want subjected to the build dependencies set in the project files.
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.