Class template specialization for implementing Automata

I’m implementing classes for simulating and generating different kind of automata. I’d prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc.

For a PDA a transition from one state to another work require some sort of an extension, because the transition requires to pop something from and push something on the stack.

So I came up with the idea to let the transitions accept a extension class as template parameter:

public class Transition<T> {

    private State target;
    private T extension;

    public Transition(State target, T extension) {
        this.target = target;
        this.extension = extension;
    }

    public State getTarget() {
        return target;
    }

    public T getExtension() {
        return extension;
    }
}

Note that there are EpsilonTransition and RegularTransition derived classes from this base class.

A PDA would require for instance this extension:

public class StackExtension {

    private Character toPop, toPush;

    public StackExtension(Character toPop, Character topush) {
        this.toPop = toPop;
        this.toPush = topush;
    }

    public Character getToPop() {
        return toPop;
    }

    public Character getToPush() {
        return toPush;
    }
}

So that the PDA class can use Transition<StackExtension> instances.

Although this is a solution for my problem, it feels like bad design. Especially for the NFA and DFA, which do not require any extension.

Is there another design pattern for my particular problem?

0

I’m not familiar with the particular automata classes you mention, but whenever you have a one-off class that you’d like to handle in similarly to the other classes, then the Facade pattern is pretty useful.

I’m over-simplifying, but the facade pattern is little more than a wrapper around the class in order to either or both of:

  • reduce the complexity of the available class methods
  • make the class conform to a particular interface

In your case, it sounds like you’re wrapping the PDA class so that it will conform to a particular set of interfaces. That’s a perfect use for the facade.

All the actual code you’ve shown doesn’t do anything, it just sets up properties, so any answer will involve some guessing.

It’s not clear to me why having an unconstrained generic type on transition makes sense. Could it take a string type? My guess is that what you are trying to do is let the “extension” class know that the transition has occurred, and perhaps some information about it.

That sounds kind of like the transition should emit a TransitionComplete event – except that events can be subscribed to by any class, making it difficult for someone reading the code to know where the event is actually consumed.

In your case, it might be more transparent if you passed your extension class in to the constructor of the of the transition class, of type ITransitionHandler, and called its TransitionComplete method.

I can’t say which is better for your program.

It’s possible to follow either of my suggestions and still make the Transition class generic, just constrained to ITransitionHandler only. But, why? The only class that really cares about the extension class’s type is the extension class itself, and it already knows. So why make that part of Transition’s type?

Again, without seeing your implementation, that may not be true, and making extension generic may be useful.

As an aside, I wouldn’t spend a huge amount of time perfecting the design. The number of automata types isn’t likely to grow very fast, and the amount of code with visibility into the details of this design is likely pretty small.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Class template specialization for implementing Automata

I’m implementing classes for simulating and generating different kind of automata. I’d prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc.

For a PDA a transition from one state to another work require some sort of an extension, because the transition requires to pop something from and push something on the stack.

So I came up with the idea to let the transitions accept a extension class as template parameter:

public class Transition<T> {

    private State target;
    private T extension;

    public Transition(State target, T extension) {
        this.target = target;
        this.extension = extension;
    }

    public State getTarget() {
        return target;
    }

    public T getExtension() {
        return extension;
    }
}

Note that there are EpsilonTransition and RegularTransition derived classes from this base class.

A PDA would require for instance this extension:

public class StackExtension {

    private Character toPop, toPush;

    public StackExtension(Character toPop, Character topush) {
        this.toPop = toPop;
        this.toPush = topush;
    }

    public Character getToPop() {
        return toPop;
    }

    public Character getToPush() {
        return toPush;
    }
}

So that the PDA class can use Transition<StackExtension> instances.

Although this is a solution for my problem, it feels like bad design. Especially for the NFA and DFA, which do not require any extension.

Is there another design pattern for my particular problem?

0

I’m not familiar with the particular automata classes you mention, but whenever you have a one-off class that you’d like to handle in similarly to the other classes, then the Facade pattern is pretty useful.

I’m over-simplifying, but the facade pattern is little more than a wrapper around the class in order to either or both of:

  • reduce the complexity of the available class methods
  • make the class conform to a particular interface

In your case, it sounds like you’re wrapping the PDA class so that it will conform to a particular set of interfaces. That’s a perfect use for the facade.

All the actual code you’ve shown doesn’t do anything, it just sets up properties, so any answer will involve some guessing.

It’s not clear to me why having an unconstrained generic type on transition makes sense. Could it take a string type? My guess is that what you are trying to do is let the “extension” class know that the transition has occurred, and perhaps some information about it.

That sounds kind of like the transition should emit a TransitionComplete event – except that events can be subscribed to by any class, making it difficult for someone reading the code to know where the event is actually consumed.

In your case, it might be more transparent if you passed your extension class in to the constructor of the of the transition class, of type ITransitionHandler, and called its TransitionComplete method.

I can’t say which is better for your program.

It’s possible to follow either of my suggestions and still make the Transition class generic, just constrained to ITransitionHandler only. But, why? The only class that really cares about the extension class’s type is the extension class itself, and it already knows. So why make that part of Transition’s type?

Again, without seeing your implementation, that may not be true, and making extension generic may be useful.

As an aside, I wouldn’t spend a huge amount of time perfecting the design. The number of automata types isn’t likely to grow very fast, and the amount of code with visibility into the details of this design is likely pretty small.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Class template specialization for implementing Automata

I’m implementing classes for simulating and generating different kind of automata. I’d prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc.

For a PDA a transition from one state to another work require some sort of an extension, because the transition requires to pop something from and push something on the stack.

So I came up with the idea to let the transitions accept a extension class as template parameter:

public class Transition<T> {

    private State target;
    private T extension;

    public Transition(State target, T extension) {
        this.target = target;
        this.extension = extension;
    }

    public State getTarget() {
        return target;
    }

    public T getExtension() {
        return extension;
    }
}

Note that there are EpsilonTransition and RegularTransition derived classes from this base class.

A PDA would require for instance this extension:

public class StackExtension {

    private Character toPop, toPush;

    public StackExtension(Character toPop, Character topush) {
        this.toPop = toPop;
        this.toPush = topush;
    }

    public Character getToPop() {
        return toPop;
    }

    public Character getToPush() {
        return toPush;
    }
}

So that the PDA class can use Transition<StackExtension> instances.

Although this is a solution for my problem, it feels like bad design. Especially for the NFA and DFA, which do not require any extension.

Is there another design pattern for my particular problem?

0

I’m not familiar with the particular automata classes you mention, but whenever you have a one-off class that you’d like to handle in similarly to the other classes, then the Facade pattern is pretty useful.

I’m over-simplifying, but the facade pattern is little more than a wrapper around the class in order to either or both of:

  • reduce the complexity of the available class methods
  • make the class conform to a particular interface

In your case, it sounds like you’re wrapping the PDA class so that it will conform to a particular set of interfaces. That’s a perfect use for the facade.

All the actual code you’ve shown doesn’t do anything, it just sets up properties, so any answer will involve some guessing.

It’s not clear to me why having an unconstrained generic type on transition makes sense. Could it take a string type? My guess is that what you are trying to do is let the “extension” class know that the transition has occurred, and perhaps some information about it.

That sounds kind of like the transition should emit a TransitionComplete event – except that events can be subscribed to by any class, making it difficult for someone reading the code to know where the event is actually consumed.

In your case, it might be more transparent if you passed your extension class in to the constructor of the of the transition class, of type ITransitionHandler, and called its TransitionComplete method.

I can’t say which is better for your program.

It’s possible to follow either of my suggestions and still make the Transition class generic, just constrained to ITransitionHandler only. But, why? The only class that really cares about the extension class’s type is the extension class itself, and it already knows. So why make that part of Transition’s type?

Again, without seeing your implementation, that may not be true, and making extension generic may be useful.

As an aside, I wouldn’t spend a huge amount of time perfecting the design. The number of automata types isn’t likely to grow very fast, and the amount of code with visibility into the details of this design is likely pretty small.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật