.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What is the best technic (vb.class)

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
edube14
602 Views, 3 Replies

What is the best technic (vb.class)

Hi guys !

 

Im really new to vb.class (Autocad)

 

As per the attached printscreen...

 

Is it better to have one file for each vb.class(like printscreen) or it's better to put it all in one vb.class ?

 

Maybe noob question, but I want to know...

 

Thanks in advance !

3 REPLIES 3
Message 2 of 4
bjhuffine
in reply to: edube14

When working with objects there are many things you have to consider.  I'm a fan of the domain driven design (DDD) philosophies.  Since you're just beginning, here's a couple of things I would start off with.  There's plenty of material out there on this and many, many books, so I would encourage you to research these.  Hopefully these concepts can be starting point as you study and build your personal knowledge base.  Bullet #2 more directly answers your question.

 

  1. Understand the difference between reference and value types.  Most of what you will use will be reference types (i.e. classes) and every now and then you'll find value types (i.e. structs) helpful.  While trying to understand this, I would also suggest you take a brief look at the CTS objects (common type system) which are also your basic types like integers, boolean, strings, etc.  You'll find some are reference and some are value types too.
  2. Remember that the job of any object is to encapsulate only one entity.  Classes can have attributes that describe it (i.e. properties) and actions (i.e. methods).  Consider for example a class called Person.  There are some principles you'll eventually want to study (I wouldn't go there right now though) that are part of the DDD philosophy on how to design your system.  The one rule I would consider though that answers your question is that each object should have ONLY ONE responsibility.  This is called the Single-Responsibility Principle.  If you build an object with more than one responsibility then your processes will be too tightly coupled and difficult to manage over time.  Consider each object as a gear in a machine.  Each should only have it's one job to consider.  As for separate files or not... definitely separate files.  There are times when you may need to nest a private class within another more accessible class, but that is rare.  Remember that the end-product is compiled.  Having separate files doesn't change how the program works and it sure makes it easier for you to find what you need.
  3. To help understand how to break objects out by their responsibility (i.e. SRP) consider the different types of objects to create by definition.  Here are a few basic types.  Note that 'objects' can be classes or structs:
  • Entity (objects that have a unique identifier to be tracked throughout its life)
  • Value Objects (not necessarily value types) (immutable objects that are disposable and do not require tracking)
  • Factory (objects that are used to simply create another object because the process is more complex than a few lines in a constructor)
  • Service (objects that perform a function... since most objects are descriptive these tend to be more functional and action-oriented... they also do not have a state, i.e. no properties)

4.  As you learn more on how to create and design your system, I would research design patterns as well.  Their intentions may not be obvious to you at first but if you get used to them they can really save the day by allowing you to create a more flexible, maintainable, and extensible system.

Message 3 of 4
edube14
in reply to: edube14

In the same subject...

 

Is it a good idea to put all functions that I used in many others classes, in a one specific file ?

 

Or, it's preferable to copy the function in each classes ?

 

Thanks again !

Message 4 of 4
bjhuffine
in reply to: edube14

Code reuse is a really big deal.  If you have methods that manage the same process repeated in several places, then any change has to be repeated with each method.  And that's if you remember where each one is located.  Chances are great that you'll miss one.  Definitely keep functionality in one operation.  Again, a lot of this depends on how you design your objects.  If, for example, you create a factory class that creates a complex object, then you have all of that object creation code in the one class (Single Responsibility Principle).  Any time you need to create the complex object, create an instance of your factory class and call it's Create()... or whatever... method.  No need having to repeat the creation code.  Object Oriented Design (OOD) means treating each class/struct like its an object that's capable of interacting with other objects.  If the function would have to be repeated with similar objects, then inheritance can be used to ensure that the function is still in one place in the base class.  For example say you have three classes Employee, Manager, and Intern.  You don't want to repeat a property that queries and returns their mailstop in each one.  But since each carry the same principle properties and methods, they could all three inherit from a Person class which would have the MailStop property and the other three would automatically inherit it.  Most of the time you can isolate your code for reuse.  Anything short of those rare exceptions I believe can create a mess down the road.

 

Another principle to consider is Inversion of Control.  IoC is a term that's been around for ages and depending on the type of development work you do can mean something slightly different.  But the point I want to get across is the idea that you don't build a class that manages the processes in one step.  That alone breaks SRP as well as Open/Closed principle, etc.  With IoC you design objects that encapsulate the functionality it's designed to manage.  Either at the application level or with a Service class you can manage the process by instantiating objects and calling the appropriate methods at the appropriate times.  Effectively inverting control from the top down to the bottom up.  Since you're just beginning, don't worry about all that.  Just remember that an object decribes an object:  Properties are attributes of the object and Methods are the actions an object can take.  From there learn how to create instances between classes and call the operations you need. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost