.net - Refactoring Inheritance To Composition Using Vbex2005?

Jul 7, 2010

I have a class that I wrote fairly early on in my vb.net programming experience which inherited from another class it really should have composed. The base class is a relatively generic nested dictionary-based collection; let's call the descendant class a "Car".Right now there's a lot of code that does things like 'MyCar!Color.st = "Red"' (I use the generic collection rather than real properties to facilitate data interchange with code written in VB6, and also to facilitate comparisons of cars; given three cars X, Y, Z, I can e.g. detect any changes between X and Y and apply those changes to Z).

Is there any nice way to refactor the code to use composition rather than inheritance?Which properties methods should the "Car" object wrap, and which ones should be accessed through a data-object property? Should a widening conversion be defined between a car and the collection object? Are there any gotchas when doing such refactoring?

View 1 Replies


ADVERTISEMENT

OOP - Objects For Entities With Master Lists And Object Composition?

Feb 23, 2009

I'm trying to wrap my head about how to properly implement an OOP design for business objects that:

Have a "master list" in a database (ex. classifications)Are a part of another object as a property (i.e. object composition) but with additional properties

Here is where I'm stuck on the theory. Suppose that I have a Classification object, inheriting from the abstract class BusinessObject with the CRUD functions defined (MustOverride). This will give me:

[Code]...

What kind of other design could I implement here? It's obvous that I'm designing this the wrong way, but I don't see an easy alternative pattern. I don't want to repeat the code in the CustomerClassification class by not inheriting Classification and repeating all the field and property code, but I also don't want to expost CRUD functions to the CustomerClassification level. What am I missing in looking at the overall class design?

EDIT: Saving the classification level to the database will be handled by the customer object, because the database is legacy and the field for Level is defined in the customer table.

View 2 Replies

IDE :: Refactoring Does Not Work (enough) In VB

Sep 28, 2009

I use VS 2005 and VB.NET. I have a class A. This class A is an empty class(no functions, no members). I wrote the following code: Dim _a as new A(); Dim code as String = _a.GetCode() In the same situation, the C# refactoring tool in VS 2005 IDE propose me to create a method in the A class internal string GetCode(){ }

The VB.NET compiles does not propose anything. There is a way to implement the functions when I need it in code, or I need to planify all my methods before using the class?

View 4 Replies

.net - Refactoring A Field Into A Property?

Jun 7, 2012

I am currently learning vb.net for my new job and I have mixed feelings over public fields. I see many arguments about them hurting the encapsulation. In python, the common practice is to keep things simple and use fields when they are enough. If we want to add logic later, we just refactor them into a property without breaking anything for the client code.In the codebase I am working with I see huge classes containing dozen of properties like:

[Code]...

View 2 Replies

How To Approach Refactoring A Class

Jul 24, 2009

I recently started a project and needed to do some integration with LDAP via DirectoryServices. I've done this in other apps so I went into one of them to see how I did it -- why reinvent the wheel right? Well, while this wheel works, it was developed years ago and kinda smells (it's wooden, firmly attached to the previous vehicle, hard to repair and produces a potentially bumpy ride).So I thought to myself, this is the perfect time to refactor this puppy and make it more portable, reusable, reliable, easier to configure etc. Now that's fine and dandy, but then I started feeling a tad overwhelmed regarding to where to start. Should it be a separate library? How should it be configured? Should it use IoC? DI?

So my [admittedly subjective] question is this -- given a relatively small, but quite useful class like the one below, what is a good approach to refactoring it? What questions do you ask and how do you decide what to implement or not implement? Where do you draw the line regarding configuration flexibility? [Note: Please don't bash this code too much okay? It was written a long time ago and has functioned perfectly well baked into an in house application.]

Public Shared Function AuthenticateUser(ByVal id As String, ByVal password As String) As Boolean
Dim path As String = GetUserPath(id)

[code]......

View 5 Replies

IDE :: Refactoring Data Contracts?

Dec 20, 2010

I want to add DataMember attributes for the properties in a class Is there any way to automatically add the attribute maybe some refactoring tool

View 4 Replies

VS 2010 Class Refactoring?

Feb 21, 2011

This is my scenario. I am writing an app which takes a person object and a features object , when the user selects a person object a features object is created. This works for any amount of features i care to display. So far so good, i am now refactoring to create 2 additional classes, a maths class and a ui class. my issue now is how do i get the maths functions to know the instance of the features object(s) or person object(s)?

Unfactored
Public Sub New(ByVal feature1 As New Feature)
...

[code].....

View 2 Replies

'The File Does Not Support Refactoring Error

Oct 13, 2010

When I try to change the root namespace of my WPF VB.Net application, I get this error:
'The file "" does not support refactoring and will have to be manually changed. Object reference not set to an instance of an object'

[Code]...

View 5 Replies

Asp.net - Refactoring: Gridview Export To CSV File

Sep 15, 2009

These routines (vb.net) allow you to dump a gridview to CSV, even if there are templated controls in the cells. It works, but I'm not thrilled with it.

What improvements should I make and why?

Private Shared Function CsvFormatted(ByVal t As String) As String
If t.Contains(",") Then
t = """" + t + """"

[Code].....

View 1 Replies

IDE :: No Free Refactoring Support For .NET In 2010?

May 21, 2010

Have we moved from "Being forced to go install a 3rd party add in to get what C# users have" to "Being forced to go buy a 3rd party add in to get what C# users have"?

Why did MS see fit to get DevExpress to create Refactor! for the previous versions of VS, but not for 2010? Or am I missing something?

View 3 Replies

VS 2008 - Refactoring Presentation Layer

Sep 10, 2010

I've been working to refactor my code and ended up with a quite clean main BLL class that has only a few manager classes that pass information between eachother. They handle separate tasks/areas like socket connection, data, etc. It's only one instance of each of these manager objects, so I believe maybe the base layout is a structural singleton (?) ..but not sure. This seems to give quite good oversight and a clean separation of PL/BLL as the main form only access the BLL through one instance of a single class. But now I'm trying to figure out how to lay out the presentation layer. So with this I would like to understand a few points: Do you have all controls as members of the form class, or can you make sub classes where some controls only exist on lower levels? Like for example if you have a tab where all controls only interact with each other, and not the rest of the form, would it then be possible to make this a separate class that holds both controls and additional logic ? The first problem I get when trying this is with the events, as if I simply move an event handler method to another class than the form class, I get the message: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.What does this mean? and is there an easy way around this? I would like to understand how a slightly more complex PL is designed, so I know what direction to move in for studying/developing this.

View 3 Replies

.net - Refactoring Of Case Statement And Dynamic Operator?

Jun 4, 2012

I have a case statement which compares data by getting parameter such as "eq,ne,gt,..." and so on. Actually this method will filter data by getting filter parameter and filter value. How can I refactor below code?

[Code]...

View 1 Replies

C# - Refactoring Tool That Works Across Solutions Files?

Feb 11, 2010

All the refactoring tools for C# and VB.Net that I have seen only consider the source code in a single visual studio solution.For better or worse, our large (many related programs) system is spread over many solution files, however:All the code is below a single windows folder. Our nAnt based build system, builds all files in a windows folder to produce a single dll (bit more complex then this but not important for this question).Therefore ALL ".cs" and ".vb" files below the single root folder are part of the system.

So I am looking for refactoring and reverse engineering tools that take a single folder as input and act on all files below that folder.(The tools may need some help to decide what "public" and "internal" means, however most of the time "internal" means "in the same code tree" when a "code tree" is a folder that contains code and any child folders.)Now I am being greedy, I would like the tools to create a lot of all the refactorings that have been done and to be able to replay the refactorings. Then I could try out ideal and if they work, throw away my code, get the latest code, you do the refactorings and checkin the code before anyone else changes the files. (Likewise for when branches need merging)

View 1 Replies

Refactoring A Method To Call A Stored Procedure?

Nov 17, 2010

I need to refactor the method GetVendorBalanceDue to call stored procedure spVendorBalance in my database. I have created the stored procedure and am not sure how to get the method to call the stored procedure. Here is my code:

Private Function GetVendorBalanceDue(ByVal vendorID As Integer) As Decimal Implements InvoiceService.GetVendorBalanceDue
Dim selectCommand As New SqlCommand

[Code].....

View 1 Replies

Prevent Data Layer Refactoring Of ODP.NET Code And Transactions?

Aug 27, 2009

I am using Oracle 11g client, with ODP.NET. I am trying to add conditional Transaction handling.

Dim ds As New DataSet()
Dim txn As OracleTransaction
Dim _beginTransaction as Bolean = true
Using conn As New OracleConnection(ConnString)

[Code]...

How do I fix txn being nothing / null? The error is: Variable 'txn' is used before it has been assigned a value. A null reference exception could result at runtime. Edit: to RichardOD for pointing out that you can not explicitly declare that a transaction cannot be opend up on stored procedures via ODP.NET. I have verified that this is an issue. BUT We still haven't figured out why the error is occuring. I understand that txn is initially given a value w/in an if statement, but being defined outside of the try/catch block should make that irrelevant.... right? Or is that bad coding?

View 3 Replies

Refactoring - Possible To Simplify (refactor) My Program Code (VB 2010)?

Jun 27, 2012

I have created a simply Pizza program (for a summer project not education related) that uses check boxes to determine what the customer wants. Basically a simple pizza ordering program.I was wondering as I have used the If statement over and other again for different parameters and variables, is it possible to use multiply arrays to simply the VB Code...I was advised to use Constructors in VB.Net Or is there a more simpler way to go about creating this program...or a better way of programing?What about decreasing the repetition in the code?

[code]...

View 4 Replies

Refactoring - Use Default Arguments That Are The Result Of A Function Call?

Jul 15, 2010

I have a whole slew of database access functions which assume a particular connection string. Within my application I call

[Code]...

View 1 Replies

Refactoring A Method To Replace Sql String With The Stringbuilder Class

Nov 3, 2010

How do I refactor the method GetInvoiceNumbers to replace the SQL String concatenation with the StringBuilder class? Here is my code:

Private Function GetInvoiceNumbers() As System.Collections.Generic.List(Of Invoice) Implements InvoiceService.GetInvoiceNumbers
Dim invoiceList As New List(Of Invoice)

[Code].....

View 3 Replies

Refactoring Options In Visual Studio 2010 Differ Between C# And VB

Oct 14, 2011

In VS2010 C#, when I right-click there is "Refactor" menu with following options:

[Code]....

Are these options available in VS2010 VB.Net? All I can see is "Rename" when I right click?

View 1 Replies

How To Use VB - Design A Program - String, Data Enadled Application And Refactoring

Jul 20, 2008

Dont understand where to start on visual basic iv been leaning alot about computers over the months and i would now like to design a program and to be honest its all new and i dont no where to start or what any of these woulds mean like string, data enadled application and refactoring.

View 3 Replies

Refactoring A Module Into A Class: Changing Shared Fields To Instance Fields

Nov 14, 2011

I'm currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:

Public Module Globaldefinitons
Public a As Short
...
Public zz10 As Double

[Code]...

I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:

globalDefinitionsInstance.a = 5

How do I go about this efficiently?

Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don't seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.

View 2 Replies

How To Apply Inheritance

Apr 22, 2012

i am just trying to apply inheritance ..Below is my Code ... on which i am not getting the output on my Text_Box ... when in write it in a Child Class

Imports System
Imports System.Windows
Imports System.Windows.Forms

[code]....

View 4 Replies

Oop - Inheritance And Interfaces ?

Jul 14, 2011

Has someone a hint what I'm doing wrong in VB.Net?

Module Module1

Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface

[CODE]...

The third cast isn't working. Why? did I miss a oop lesson?

View 2 Replies

Why Only One Parent In Inheritance

Mar 2, 2011

What's the choice design that microsoft do that? Of course, as of me, I don't use inheritance a lot, or at all.

View 14 Replies

.net - Inheritance And Collection Of Objects?

Oct 21, 2011

we have 3 classes:Class S, class A, class B / A and B inherits S.A has a property A1 and B has a property B1.we also have a collection of objects that has A and B objects.ex.

Dim c as Collection = new Collection
c.add(new A)
c.add(new B)

Now we want to make a general object that will read from the collection.

ex .
Dim obj as S

how can we cast obj in order to see properties A1 or B1 according to the class;

View 1 Replies

.net - Inheritance Works For First Descendant But Not Next?

Apr 20, 2011

Form1
Public Class Form1
Private Sub But_Bell_Click(sender As System.Object, e As System.EventArgs) Handles But_Bell.Click
MessageBox.Show("Ding a ling")
End Sub

[code]....

Where has the whistle button gone? The class part of the inheritance has works because you can access it via code.

View 1 Replies

.NET Constructor With Parameters And Inheritance?

Jun 29, 2010

Why VB.NET (vs C#) does not "inherit" the constructors with parameters?

Public Class StopLine
Inherits Microsoft.VisualBasic.PowerPacks.LineShape
Public Sub New()
MyBase.New()

[code]....

View 1 Replies

.net Multiple Inheritance In An Interface?

Apr 15, 2011

I'm facing a problem regarding multiple inheritance in VB.net:As far as I know VB.net does not support multiple inheritance in general but you can reach a kind of multiple inheritance by working with interfaces (using "Implements" instead of "Inherits"):

Public Class ClassName
Implements BaseInterface1, BaseInterface2
End Class

That works fine for classes but I'd like to have an interface inheriting some base interfaces. Something like that:

[Code]...

View 3 Replies

C# - Appropriate To Use Generics Versus Inheritance?

Apr 28, 2009

What are the situations and their associated benefits of using Generics over Inheritance and vice-versa, and how should they be best combined?I'm going to try to state the motivation for this question as best I can:I have a class as shown below:

[Code]...

Now suppose I have a repository that takes an InformationReturn argument, that has to strore different fields in a DB depending on the type of Info object T is. Is it better to create different repositories each for the type T is; one repository that uses reflection to determine the type; or is there a better way using inheritance capabilities over/with generics?

View 6 Replies

C# - Serialization Across Projects With Inheritance?

Jul 19, 2010

I have a base class ("MyBaseClass") in a project called "BaseFramework" which is included in several solutions within the company. There are several derived class's in various projects throughout the company that inherit from "MyBaseClass". If I then create a List and add derived class's to it, it will not serialize. I realise that if I were attempting to serialize this list, and the base class and derived class were in the same project, I could simply apply the "XmlInclude" attribute to the base class and include all of the derived class's. This is however not possible across projects, because that would require a circular dependency.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved