Hi everyone,
I’m working on a project where I need to compile two independent modules together:
NFXML.prg – legacy code that builds the entire NF-e object model.
NFComXML.prg – new code that builds the NF-Com object model.
Both files are generated automatically (they can’t be merged easily) and each contains dozens of CREATE CLASS … blocks.
The problem is that several class names repeat in the two PRGs, and their definitions are not identical.
A minimal example:
*-- in NFXML.prg -----------------
CREATE CLASS Cofins
VAR CST, vBC, pCofins, vCofins, qBCProd, vAliqProd
METHOD new() CONSTRUCTOR
METHOD toHash()
METHOD toJson() INLINE hb_jsonEncode( Self:toHash(), .T. )
ENDCLASS
*-- in NFComXML.prg --------------
CREATE CLASS Cofins
VAR CST, vBC, pCofins, vCofins && ← fewer vars, slightly different meaning
METHOD new() CONSTRUCTOR
METHOD toHash()
METHOD toJson() INLINE hb_jsonEncode( Self:toHash(), .T. )
ENDCLASS
When I compile the two PRGs together (Harbour 3.2.0dev + hbmk2) the compiler, as expected, reports that the class “Cofins” is already defined.
Question:
Is there any clean way (namespaces, static libraries, conditional compilation, etc.) to let two PRGs expose classes with the same identifier but different implementations, so that each module can keep its own definition?
Constraints / context:
Refactoring the generators to rename every duplicate class would be painful – the list is fairly long (Cofins, Pis, Icms, Totais, etc.).
At runtime the two object trees (NFXml and NFComXml) never mix – they are instantiated separately.
If the answer is “no, Harbour’s OOP model doesn’t allow duplicate class names in the same build”, that’s fine – I’ll look into renaming or pulling one set into a DLL/SO. But I’d love to confirm before going down that path.
Thanks in advance for any guidance or patterns you may have used in similar situations!
Caro colega estou desenvolvendo classe para nfe/nfce (não trabalho com nfecom), mas daria para acrescentar na classe. Se deseja conhecer a classe está em https://github.com/malcarli1/Nfe_Classe . Acho que serviria como base de estudo. Não sou craque em classe, mas me viro
Att.
Marcelo A. L. Carli
Marília/SP
Capital Nacional do Alimento ®
https://malc-informatica.ueniweb.com
Insta: @malcarli25
Email / Skype: marcelo...@gmail.com
******************************************************************************
Se for repassar, apague o meu nome e endereço.
Ajude a combater a propagação de vírus e spams
coloque TODOS os destinatários em CÓPIA OCULTA (Cco / Bcc)
******************************************************************************
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/3f93c6bb-2bb9-457f-9ac0-49068943486fn%40googlegroups.com.
oClass := MyCrazyClass(1)
oClass2 := MyCrazyClass(2)
oClass3 := MyCrazyClass(3)
FUNCTION MyCrazyClass( nType )
LOCAL oClass
DO CASE
CASE nType == 1; oClass := Class1():New()
CASE nType == 2; oClass := Class2():New()
CASE nType == 3; oClass := Class3():New()
ENDCASE
CREATE CLASS Class1 STATIC
...
CREATE CLASS Class2 STATIC
...
or,,, not sure about your needs
oProduto := Produto():New()
oProduto:Icms:Base := 10
oProduto:Icms:Aliquota := 10
oProduto:Ipi:Base := 10
....
CREATE CLASS Produto
VAR Icms
VAR Ipi
VAR Pis
Method New() CLASS Produto
::Icms := ImpostoClass():New()
::ipi := ImpostoClass():New()
::Pis := ImpostoClass():New
...
CREATE CLASS Impostoclass STATIC
VAR Base INIT 0
VAR Aliquota INIT 0
VAR Valor INIT 0
ENDCLASS
José M. C. Quintas
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/42c33b9c-41ef-4448-9bfd-9cfccdf58ec8n%40googlegroups.com.