설계의 고민 (시리얼 포트 연결 설정 클래스의 위치?? 선언??)

punxism의 이미지

프로젝트를 간단히 설명하자면 자바로 시리얼 통신을 이용하여 문자열을 얻어와 여러가지 데이터를 뽑아 내는 것입니다.

우선 시리얼 포트 하나를 열어 연결을 시킵니다.
데이터를 뽑아 오는 종류에 따라 A,B,C로 나누어 지기 때문에
Class Info를 선언하고

Class A extends info
Class B extends info
Class C extends info

로 선언 했습니다.

그리고

Class StSoket 을 선언해 시리얼 포트 연결 설정을 합니다.

그럼 A, B, C에서 StSoket의 객체를 가지고 문자열을 얻어와 각각의 알고리즘으로 정보를 뽑아 냅니다.
A, B, C에서 StSoket을 이용하기 위해
Class A
{
StSoket a;
public void A(StSoket a)
{
this.a = a;
}
}

이렇게 했습니다. 그리고 Main에서 A를 선언하면서 하나의 StSoket을 다 넘겨주게 됩니다.

이렇게 하려고 했는데 왠지 마음에 들지 않아
일단 소켓 통신하는 Manager를 만들었습니다.
(StSokect은 구조적 동작을 하고 Manager에서는 문자열을 얻어와 두개를 리턴 한다던지 문자열 전체를 리턴 하다던지 하는
식으로 이용할 생각입니다.)

다시 위의 코드와 같이 넘기려고 하니 다시 마음에 들지 않았습니다.
Main에서 Manager를 하나씩 넘겨줘야 한다는것이 마음에 들지 않았습니다.

이럴 경우 어떻게 Manage를 잘 넘겨 줄 수 있을가요?

시리얼 포트 연결 설정은 하나만 되어야 하기 때문에 Manager는 하나만 선언 되어야하고 포인터만 참조 해야하는데
어떤 식으로 해야 할지 개념이 잘 잡히지 않습니다.

오랜 만에 자바를 잡았는데 너무 슬픕니다. ㅜㅜ
좋은 의견 있으시면 감사드립니다.

kewlbear의 이미지

Manager가 하나만 있어야 한다는 게 포인트라면 singleton 패턴을 사용하시는 것도 생각해보세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.